mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-21 11:16:16 +02:00
(cat): Don't advance the write pointer past the end of the write buffer.
This commit is contained in:
@@ -265,19 +265,21 @@ cat (
|
|||||||
if (outbuf + outsize <= bpout)
|
if (outbuf + outsize <= bpout)
|
||||||
{
|
{
|
||||||
char *wp = outbuf;
|
char *wp = outbuf;
|
||||||
|
size_t remaining_bytes;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
|
if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
|
||||||
error (EXIT_FAILURE, errno, _("write error"));
|
error (EXIT_FAILURE, errno, _("write error"));
|
||||||
wp += outsize;
|
wp += outsize;
|
||||||
|
remaining_bytes = bpout - wp;
|
||||||
}
|
}
|
||||||
while (wp + outsize <= bpout);
|
while (outsize <= remaining_bytes);
|
||||||
|
|
||||||
/* Move the remaining bytes to the beginning of the
|
/* Move the remaining bytes to the beginning of the
|
||||||
buffer. */
|
buffer. */
|
||||||
|
|
||||||
memmove (outbuf, wp, bpout - wp);
|
memmove (outbuf, wp, remaining_bytes);
|
||||||
bpout = outbuf + (bpout - wp);
|
bpout = outbuf + remaining_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is INBUF empty? */
|
/* Is INBUF empty? */
|
||||||
|
|||||||
Reference in New Issue
Block a user