]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: fix ptrdiff_t/ssize_t theoretical glitches
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 Nov 2021 00:10:21 +0000 (16:10 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 Nov 2021 00:11:27 +0000 (16:11 -0800)
* src/copy.c (sparse_copy): Use system.h’s SSIZE_MAX.
Don’t assume SSIZE_MAX <= PTRDIFF_MAX.

src/copy.c

index f88bf3ed31fd8d4e5ab1bc30fd808574055cf62e..f30d984d1a1739e9167ad0907d008a24109b0ff2 100644 (file)
@@ -313,10 +313,9 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
     while (max_n_read)
       {
         /* Copy at most COPY_MAX bytes at a time; this is min
-           (PTRDIFF_MAX, SIZE_MAX) truncated to a value that is
+           (SSIZE_MAX, SIZE_MAX) truncated to a value that is
            surely aligned well.  */
-        ssize_t ssize_max = TYPE_MAXIMUM (ssize_t);
-        ptrdiff_t copy_max = MIN (ssize_max, SIZE_MAX) >> 30 << 30;
+        ssize_t copy_max = MIN (SSIZE_MAX, SIZE_MAX) >> 30 << 30;
         ssize_t n_copied = copy_file_range (src_fd, NULL, dest_fd, NULL,
                                             MIN (max_n_read, copy_max), 0);
         if (n_copied == 0)