]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(simple_cat): Use a temporary to avoid bogus warnings.
authorJim Meyering <jim@meyering.net>
Sun, 29 Sep 2002 21:25:03 +0000 (21:25 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 29 Sep 2002 21:25:03 +0000 (21:25 +0000)
(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

index e78b4bde9285403bf9f27bfa249d234bd9a6478f..4c42f44df106542a32f19649f6ce0ff4802b1ce1 100644 (file)
--- 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;