stagit-gopher

[fork] gopher git frontend
Log | Files | Refs | README | LICENSE

commit 45274ebb4ba07c9771c279aae51259040d94d0ab
parent bbd27612e48b51f37e4e70566ded2007fe48724f
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:
Mstagit-gopher-index.c | 12++++++------
Mstagit-gopher.c | 14+++++++-------
2 files changed, 13 insertions(+), 13 deletions(-)

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; } } 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; } }