sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 9046323df9d6160f71f6f45dcf1c41ccf30b9fda
parent bb4020432b40e653b95e89631e0a4d25e1376b80
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu Feb 25 21:42:36 +0100

fix length after '\' getline string termination

Diffstat:
cut.c | 4++--
head.c | 2+-
sed.c | 4++--
tail.c | 2+-
uudecode.c | 4++--
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/cut.c b/cut.c @@ -115,8 +115,8 @@ cut(FILE *fp, const char *fname) Range *r; while ((len = getline(&buf, &size, fp)) > 0) { - if (len && buf[len - 1] == '\n') - buf[len - 1] = '\0'; + if (buf[len - 1] == '\n') + buf[--len] = '\0'; if (mode == 'f' && !utfutf(buf, delim)) { if (!sflag) puts(buf); diff --git a/head.c b/head.c @@ -15,7 +15,7 @@ head(FILE *fp, const char *fname, size_t n) while (i < n && (len = getline(&buf, &size, fp)) > 0) { fputs(buf, stdout); - i += (len && (buf[len - 1] == '\n')); + i += (buf[len - 1] == '\n'); } free(buf); if (ferror(fp)) diff --git a/sed.c b/sed.c @@ -441,8 +441,8 @@ read_line(FILE *f, String *s) eprintf("getline:"); return EOF; } - if (s->str[--len] == '\n') - s->str[len] = '\0'; + if (s->str[len] == '\n') + s->str[--len] = '\0'; return 0; } diff --git a/tail.c b/tail.c @@ -23,7 +23,7 @@ dropinit(FILE *fp, const char *str, size_t n) if (mode == 'n') { while (i < n && (len = getline(&buf, &size, fp)) > 0) - if (len > 0 && buf[len - 1] == '\n') + if (buf[len - 1] == '\n') i++; } else { while (i < n && (len = efgetrune(&r, fp, str))) diff --git a/uudecode.c b/uudecode.c @@ -169,9 +169,9 @@ uudecode(FILE *fp, FILE *outfp) while ((len = getline(&bufb, &n, fp)) > 0) { p = bufb; /* trim newlines */ - if (!len || bufb[len - 1] != '\n') + if (bufb[len - 1] != '\n') eprintf("no newline found, aborting\n"); - bufb[len - 1] = '\0'; + bufb[--len] = '\0'; /* check for last line */ if ((i = DEC(*p)) <= 0)