From: Jim Meyering Date: Tue, 8 Oct 2002 06:21:31 +0000 (+0000) Subject: (cat): Don't advance the write pointer past the end of the write buffer. X-Git-Tag: v4.5.3~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f4fb36645bc959e71b4ad871fa28755325359fc;p=thirdparty%2Fcoreutils.git (cat): Don't advance the write pointer past the end of the write buffer. --- diff --git a/src/cat.c b/src/cat.c index d547084efa..9845e58124 100644 --- a/src/cat.c +++ b/src/cat.c @@ -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? */