[hackers] [sbase] Revert "fix length after '\' getline string termination" || sin

From: <git_AT_suckless.org>
Date: Tue, 1 Mar 2016 16:24:36 +0100 (CET)

commit ea0d16e928c8b48adcb04451fc2cb63312be7b73
Author: sin <sin_AT_2f30.org>
AuthorDate: Tue Mar 1 15:23:23 2016 +0000
Commit: sin <sin_AT_2f30.org>
CommitDate: Tue Mar 1 15:24:32 2016 +0000

    Revert "fix length after '\' getline string termination"
    
    Caused a regression in sed, revert until we investigate further.

diff --git a/cut.c b/cut.c
index 4719c8b..0258271 100644
--- a/cut.c
+++ b/cut.c
_AT_@ -115,8 +115,8 @@ cut(FILE *fp, const char *fname)
         Range *r;
 
         while ((len = getline(&buf, &size, fp)) > 0) {
- if (buf[len - 1] == '\n')
- buf[--len] = '\0';
+ if (len && buf[len - 1] == '\n')
+ buf[len - 1] = '\0';
                 if (mode == 'f' && !utfutf(buf, delim)) {
                         if (!sflag)
                                 puts(buf);
diff --git a/head.c b/head.c
index bece31b..a99b6f4 100644
--- a/head.c
+++ b/head.c
_AT_@ -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 += (buf[len - 1] == '\n');
+ i += (len && (buf[len - 1] == '\n'));
         }
         free(buf);
         if (ferror(fp))
diff --git a/sed.c b/sed.c
index 819a944..6cfd121 100644
--- a/sed.c
+++ b/sed.c
_AT_@ -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
index 9addb0d..4ab5fde 100644
--- a/tail.c
+++ b/tail.c
_AT_@ -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 (buf[len - 1] == '\n')
+ if (len > 0 && buf[len - 1] == '\n')
                                 i++;
         } else {
                 while (i < n && (len = efgetrune(&r, fp, str)))
diff --git a/uudecode.c b/uudecode.c
index 28e9147..1d0bf72 100644
--- a/uudecode.c
+++ b/uudecode.c
_AT_@ -169,9 +169,9 @@ uudecode(FILE *fp, FILE *outfp)
         while ((len = getline(&bufb, &n, fp)) > 0) {
                 p = bufb;
                 /* trim newlines */
- if (bufb[len - 1] != '\n')
+ if (!len || bufb[len - 1] != '\n')
                         eprintf("no newline found, aborting\n");
- bufb[--len] = '\0';
+ bufb[len - 1] = '\0';
 
                 /* check for last line */
                 if ((i = DEC(*p)) <= 0)
Received on Tue Mar 01 2016 - 16:24:36 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 01 2016 - 16:36:18 CET