libutil/getlines: use known line length

This commit is contained in:
Hiltjo Posthuma 2015-05-05 13:42:56 +02:00 committed by sin
parent 72250324b1
commit bd67e7d92d

View File

@ -22,7 +22,7 @@ getlines(FILE *fp, struct linebuf *b)
b->lines[b->nlines - 1] = memcpy(emalloc(linelen), line, linelen);
}
free(line);
if (b->lines && b->nlines && !strchr(b->lines[b->nlines - 1], '\n')) {
if (b->lines && b->nlines && b->lines[b->nlines - 1][linelen - 1] != '\n') {
b->lines[b->nlines - 1] = erealloc(b->lines[b->nlines - 1], linelen + 1);
b->lines[b->nlines - 1][linelen - 1] = '\n';
b->lines[b->nlines - 1][linelen] = '\0';