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.
This commit is contained in:
Paul Eggert committed 2021-11-16 16:11:27 -08:00
1 parent eae8df0d94
commit 08930f21cb
1 file changed
+2 -3
+2 -3
View 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)