mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
(readline): Leave room for an extra byte
after the newline; comm needs this for memcoll.
This commit is contained in:
1 parent
115372366e
commit
bfd09e35cc
1 file changed
+4
-3
+4
-3
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user