gphtext() and gphlink(): fix NUL byte check - stagit-gopher - A git gopher frontend. (mirror)
 (HTM) git clone git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 45274ebb4ba07c9771c279aae51259040d94d0ab
 (DIR) parent bbd27612e48b51f37e4e70566ded2007fe48724f
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sat, 25 Nov 2017 15:12:36 +0100
       
       gphtext() and gphlink(): fix NUL byte check
       
       these functions iterate until the length or when there is a NUL byte.
       
       Diffstat:
         M stagit-gopher-index.c               |      12 ++++++------
         M stagit-gopher.c                     |      14 +++++++-------
       
       2 files changed, 13 insertions(+), 13 deletions(-)
       ---
 (DIR) diff --git a/stagit-gopher-index.c b/stagit-gopher-index.c
       @@ -75,8 +75,8 @@ gphtext(FILE *fp, const char *s, size_t len)
        {
                size_t i;
        
       -        for (i = 0; *s && i < len; i++) {
       -                switch (s[i]) {
       +        for (i = 0; *s && i < len; s++, i++) {
       +                switch (*s) {
                        case '\r': /* ignore CR */
                        case '\n': /* ignore LF */
                                break;
       @@ -84,7 +84,7 @@ gphtext(FILE *fp, const char *s, size_t len)
                                fputs("        ", fp);
                                break;
                        default:
       -                        fputc(s[i], fp);
       +                        fputc(*s, fp);
                                break;
                        }
                }
       @@ -96,8 +96,8 @@ gphlink(FILE *fp, const char *s, size_t len)
        {
                size_t i;
        
       -        for (i = 0; *s && i < len; i++) {
       -                switch (s[i]) {
       +        for (i = 0; *s && i < len; s++, i++) {
       +                switch (*s) {
                        case '\r': /* ignore CR */
                        case '\n': /* ignore LF */
                                break;
       @@ -108,7 +108,7 @@ gphlink(FILE *fp, const char *s, size_t len)
                                fputs("\\|", fp);
                                break;
                        default:
       -                        fputc(s[i], fp);
       +                        fputc(*s, fp);
                                break;
                        }
                }
 (DIR) diff --git a/stagit-gopher.c b/stagit-gopher.c
       @@ -297,7 +297,7 @@ gphtextnl(FILE *fp, const char *s, size_t len)
        {
                size_t i, n = 0;
        
       -        for (i = 0; *s && i < len; i++) {
       +        for (i = 0; s[i] && i < len; i++) {
                        if (s[i] == '\n')
                                n = 0;
        
       @@ -323,8 +323,8 @@ gphtext(FILE *fp, const char *s, size_t len)
        {
                size_t i;
        
       -        for (i = 0; *s && i < len; i++) {
       -                switch (s[i]) {
       +        for (i = 0; *s && i < len; s++, i++) {
       +                switch (*s) {
                        case '\r': /* ignore CR */
                        case '\n': /* ignore LF */
                                break;
       @@ -332,7 +332,7 @@ gphtext(FILE *fp, const char *s, size_t len)
                                fputs("        ", fp);
                                break;
                        default:
       -                        fputc(s[i], fp);
       +                        fputc(*s, fp);
                                break;
                        }
                }
       @@ -344,8 +344,8 @@ gphlink(FILE *fp, const char *s, size_t len)
        {
                size_t i;
        
       -        for (i = 0; *s && i < len; i++) {
       -                switch (s[i]) {
       +        for (i = 0; *s && i < len; s++, i++) {
       +                switch (*s) {
                        case '\r': /* ignore CR */
                        case '\n': /* ignore LF */
                                break;
       @@ -356,7 +356,7 @@ gphlink(FILE *fp, const char *s, size_t len)
                                fputs("\\|", fp);
                                break;
                        default:
       -                        fputc(s[i], fp);
       +                        fputc(*s, fp);
                                break;
                        }
                }