1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-12 15:06:44 +02:00

(cat): Don't advance the write pointer past the end of the write buffer.

This commit is contained in:
Jim Meyering
2002-10-08 06:21:31 +00:00
parent 7a58f340c1
commit 5f4fb36645

View File

@@ -265,19 +265,21 @@ cat (
if (outbuf + outsize <= bpout)
{
char *wp = outbuf;
size_t remaining_bytes;
do
{
if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
error (EXIT_FAILURE, errno, _("write error"));
wp += outsize;
remaining_bytes = bpout - wp;
}
while (wp + outsize <= bpout);
while (outsize <= remaining_bytes);
/* Move the remaining bytes to the beginning of the
buffer. */
memmove (outbuf, wp, bpout - wp);
bpout = outbuf + (bpout - wp);
memmove (outbuf, wp, remaining_bytes);
bpout = outbuf + remaining_bytes;
}
/* Is INBUF empty? */