From: Paul Eggert Date: Wed, 17 Nov 2021 00:10:21 +0000 (-0800) Subject: cp: fix ptrdiff_t/ssize_t theoretical glitches X-Git-Tag: v9.1~183 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08930f21cb9a330a9995de607e7df7bbeee2a890;p=thirdparty%2Fcoreutils.git cp: fix ptrdiff_t/ssize_t theoretical glitches * src/copy.c (sparse_copy): Use system.h’s SSIZE_MAX. Don’t assume SSIZE_MAX <= PTRDIFF_MAX. --- diff --git a/src/copy.c b/src/copy.c index f88bf3ed31..f30d984d1a 100644 --- a/src/copy.c +++ b/src/copy.c @@ -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)