summaryrefslogtreecommitdiff
path: root/lib/linebuffer.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-07-04 10:31:01 +0000
committerJim Meyering <jim@meyering.net>1999-07-04 10:31:01 +0000
commitbfd09e35ccd193f01437a73a7cf5b9365f48d729 (patch)
treee542c2063678b7a48514aa04494d8b4f13c9e26d /lib/linebuffer.c
parent115372366e5c36d3afe9c07f8d1dd430de821716 (diff)
downloadcoreutils-bfd09e35ccd193f01437a73a7cf5b9365f48d729.tar.xz
(readline): Leave room for an extra byte
after the newline; comm needs this for memcoll.
Diffstat (limited to 'lib/linebuffer.c')
-rw-r--r--lib/linebuffer.c7
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;
}