diff options
author | Jim Meyering <jim@meyering.net> | 1999-07-04 10:31:01 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-07-04 10:31:01 +0000 |
commit | bfd09e35ccd193f01437a73a7cf5b9365f48d729 (patch) | |
tree | e542c2063678b7a48514aa04494d8b4f13c9e26d | |
parent | 115372366e5c36d3afe9c07f8d1dd430de821716 (diff) | |
download | coreutils-bfd09e35ccd193f01437a73a7cf5b9365f48d729.tar.xz |
(readline): Leave room for an extra byte
after the newline; comm needs this for memcoll.
-rw-r--r-- | lib/linebuffer.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/linebuffer.c b/lib/linebuffer.c index b7e875be7..d129d307d 100644 --- a/lib/linebuffer.c +++ b/lib/linebuffer.c @@ -40,7 +40,8 @@ initbuffer (struct linebuffer *linebuffer) /* Read an arbitrarily long line of text from STREAM into LINEBUFFER. Keep the newline; append a newline if it's the last line of a file - that ends in a non-newline character. Do not null terminate. + that ends in a non-newline character. Do not null terminate, + but leave room for an extra byte after the newline. Return LINEBUFFER, except at end of file return 0. */ struct linebuffer * @@ -49,7 +50,7 @@ readline (struct linebuffer *linebuffer, FILE *stream) int c; char *buffer = linebuffer->buffer; char *p = linebuffer->buffer; - char *end = buffer + linebuffer->size; /* Sentinel. */ + char *end = buffer + linebuffer->size - 1; /* Sentinel. */ if (feof (stream) || ferror (stream)) return 0; @@ -71,7 +72,7 @@ readline (struct linebuffer *linebuffer, FILE *stream) buffer = (char *) xrealloc (buffer, linebuffer->size); p = p - linebuffer->buffer + buffer; linebuffer->buffer = buffer; - end = buffer + linebuffer->size; + end = buffer + linebuffer->size - 1; } *p++ = c; } |