Multiple printf() size fixes (#17199)

cmd/zinject/zinject.c:
 - use PRIu64 when printing uint64_t

tests/zfs-tests/cmd/clonefile.c:
 - use an unsigned long long to store result from strtoull()
 - use %jd for printing off_t, %zu for size_t, %zd for ssize_t

tests/zfs-tests/tests/functional/vdev_disk/page_alignment.c:
 - use %zx to print size_t

Discovered when compiling on FreeBSD i386.

Signed-off-by: Martin Matuska <mm@FreeBSD.org>

Reviewed-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Allan Jude <allan@klarasystems.com>
Reviewed-by: @ImAwsumm
This commit is contained in:
Martin Matuška 2025-04-02 00:27:03 +02:00 committed by Tony Hutter
parent 6f2080f1ab
commit 5fb1d520fe
2 changed files with 11 additions and 8 deletions

View File

@ -205,6 +205,7 @@ main(int argc, char **argv)
loff_t soff = 0, doff = 0; loff_t soff = 0, doff = 0;
size_t len = SSIZE_MAX; size_t len = SSIZE_MAX;
unsigned long long len2;
if ((argc-optind) == 5) { if ((argc-optind) == 5) {
soff = strtoull(argv[optind+2], NULL, 10); soff = strtoull(argv[optind+2], NULL, 10);
if (soff == ULLONG_MAX) { if (soff == ULLONG_MAX) {
@ -220,11 +221,13 @@ main(int argc, char **argv)
strcmp(argv[optind+4], "all") == 0) { strcmp(argv[optind+4], "all") == 0) {
len = SSIZE_MAX; len = SSIZE_MAX;
} else { } else {
len = strtoull(argv[optind+4], NULL, 10); len2 = strtoull(argv[optind+4], NULL, 10);
if (len == ULLONG_MAX) { if (len2 == ULLONG_MAX) {
fprintf(stderr, "invalid length"); fprintf(stderr, "invalid length");
return (1); return (1);
} }
if (len2 < SSIZE_MAX)
len = (size_t)len2;
} }
} }
@ -268,7 +271,7 @@ main(int argc, char **argv)
off_t dpos = lseek(dfd, 0, SEEK_CUR); off_t dpos = lseek(dfd, 0, SEEK_CUR);
off_t dlen = lseek(dfd, 0, SEEK_END); off_t dlen = lseek(dfd, 0, SEEK_END);
fprintf(stderr, "file offsets: src=%lu/%lu; dst=%lu/%lu\n", fprintf(stderr, "file offsets: src=%jd/%jd; dst=%jd/%jd\n",
spos, slen, dpos, dlen); spos, slen, dpos, dlen);
} }
@ -331,7 +334,7 @@ do_copyfilerange(int sfd, int dfd, loff_t soff, loff_t doff, size_t len)
} }
if (copied != len) { if (copied != len) {
fprintf(stderr, "copy_file_range: copied less than requested: " fprintf(stderr, "copy_file_range: copied less than requested: "
"requested=%lu; copied=%lu\n", len, copied); "requested=%zu; copied=%zd\n", len, copied);
return (1); return (1);
} }
return (0); return (0);

View File

@ -421,14 +421,14 @@ run_test(const page_test_t *test, bool verbose)
size_t take = MIN(rem, len); size_t take = MIN(rem, len);
if (verbose) if (verbose)
printf(" page %d [off %lx len %lx], " printf(" page %d [off %zx len %zx], "
"rem %lx, take %lx\n", "rem %zx, take %zx\n",
i, off, len, rem, take); i, off, len, rem, take);
if (vdev_disk_check_alignment_cb(NULL, off, take, &s)) { if (vdev_disk_check_alignment_cb(NULL, off, take, &s)) {
if (verbose) if (verbose)
printf(" ABORT: misalignment detected, " printf(" ABORT: misalignment detected, "
"rem %lx\n", rem); "rem %zx\n", rem);
return (false); return (false);
} }
@ -439,7 +439,7 @@ run_test(const page_test_t *test, bool verbose)
if (rem > 0) { if (rem > 0) {
if (verbose) if (verbose)
printf(" ABORT: ran out of pages, rem %lx\n", rem); printf(" ABORT: ran out of pages, rem %zx\n", rem);
return (false); return (false);
} }