From 7e1ff0b4f823fb3ae890d7a66ff87566d31e535c Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 29 Sep 2002 21:25:03 +0000 Subject: (simple_cat): Use a temporary to avoid bogus warnings. (cat): Declare insize and outsize to be of type size_t, not int. Rearrange pointer/integer expressions to avoid bogus warnings. (main): Declare insize and outsize to be of type size_t, not int. --- src/cat.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/cat.c b/src/cat.c index e78b4bde9..4c42f44df 100644 --- a/src/cat.c +++ b/src/cat.c @@ -182,8 +182,12 @@ simple_cat ( /* Write this block out. */ - if (full_write (STDOUT_FILENO, buf, n_read) != n_read) - error (EXIT_FAILURE, errno, _("write error")); + { + /* The following is ok, since we know that 0 < n_read. */ + size_t n = n_read; + if (full_write (STDOUT_FILENO, buf, n) != n) + error (EXIT_FAILURE, errno, _("write error")); + } } } @@ -199,13 +203,13 @@ cat ( char *inbuf, /* Number of characters read in each read call. */ - int insize, + size_t insize, /* Pointer to the beginning of the output buffer. */ char *outbuf, /* Number of characters written by each write call. */ - int outsize, + size_t outsize, /* Variables that have values according to the specified options. */ int quote, @@ -258,7 +262,7 @@ cat ( { /* Write if there are at least OUTSIZE bytes in OUTBUF. */ - if (bpout - outbuf >= outsize) + if (outbuf + outsize <= bpout) { char *wp = outbuf; do @@ -267,7 +271,7 @@ cat ( error (EXIT_FAILURE, errno, _("write error")); wp += outsize; } - while (bpout - wp >= outsize); + while (wp + outsize <= bpout); /* Move the remaining bytes to the beginning of the buffer. */ @@ -497,10 +501,10 @@ int main (int argc, char **argv) { /* Optimal size of i/o operations of output. */ - int outsize; + size_t outsize; /* Optimal size of i/o operations of input. */ - int insize; + size_t insize; /* Pointer to the input buffer. */ char *inbuf; -- cgit v1.2.3-54-g00ecf