]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: simplify integer overflow checking
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 3 Oct 2019 19:35:44 +0000 (12:35 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 3 Oct 2019 19:41:51 +0000 (12:41 -0700)
* src/copy.c (sparse_copy): Use INT_ADD_WRAPV instead
of doing overflow checking by hand.

src/copy.c

index 65cf6589532c042e3b787fc589f8b5489b3f6e8f..cd6104c7a6ce9480ffb2a49d3a70f5ccedf49531 100644 (file)
@@ -335,9 +335,7 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
             }
           else  /* Coalesce writes/seeks.  */
             {
-              if (psize <= OFF_T_MAX - csize)
-                psize += csize;
-              else
+              if (INT_ADD_WRAPV (psize, csize, &psize))
                 {
                   error (0, 0, _("overflow reading %s"), quoteaf (src_name));
                   return false;