Revert "fix length after '\' getline string termination"

Caused a regression in sed, revert until we investigate further.
This commit is contained in:
sin 2016-03-01 15:23:23 +00:00
parent fa18379a05
commit ea0d16e928
5 changed files with 8 additions and 8 deletions

4
cut.c
View File

@ -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);

2
head.c
View File

@ -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))

4
sed.c
View File

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

2
tail.c
View File

@ -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)))

View File

@ -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)