[PATCH 1/2] xfs_repair: fix printf format specifiers on 32-bit platforms

Darrick J. Wong
2022-08-09T21:07:20Z

From: Darrick J. Wong <djwong@kernel.org>

armv7l builds spit out the following warnings:

In file included from ../include/platform_defs.h:44,
from ../include/libxfs.h:13,
from bmap.c:7:
bmap.c: In function ‘blkmap_alloc’:
bmap.c:41:11: error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘xfs_extnum_t’ {aka ‘long long unsigned int’} [-Werror=format=]
41 | _("Number of extents requested in blkmap_alloc (%d) overflows 32 bits.\n"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bmap.c:41:9: note: in expansion of macro ‘_’
41 | _("Number of extents requested in blkmap_alloc (%d) overflows 32 bits.\n"
| ^
bmap.c:41:58: note: format string is defined here
41 | _("Number of extents requested in blkmap_alloc (%d) overflows 32 bits.\n"
| ~^
| |
| int
| %lld
In file included from ../include/platform_defs.h:44,
from ../include/libxfs.h:13,
from bmap.c:7:
bmap.c:54:35: error: format ‘%zu’ expects argument of type ‘size_t’, but argument 2 has type ‘xfs_extnum_t’ {aka ‘long long unsigned int’} [-Werror=format=]
54 | do_warn(_("malloc failed in blkmap_alloc (%zu bytes)\n"),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bmap.c:54:33: note: in expansion of macro ‘_’
54 | do_warn(_("malloc failed in blkmap_alloc (%zu bytes)\n"),
| ^
bmap.c:54:69: note: format string is defined here
54 | do_warn(_("malloc failed in blkmap_alloc (%zu bytes)\n"),
| ~~^
| |
| unsigned int
| %llu

Fix these.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
logprint/log_misc.c | 8 ++++----
repair/bmap.c | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 82e1f682..836156e0 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -493,16 +493,16 @@ xlog_print_trans_inode_core(
nextents = ip->di_big_nextents;
else
nextents = ip->di_nextents;
- printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%lx\n"),
+ printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%llx\n"),
(unsigned long long)ip->di_size, (unsigned long long)ip->di_nblocks,
- ip->di_extsize, nextents);
+ ip->di_extsize, (unsigned long long)nextents);

if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
nextents = ip->di_big_anextents;
else
nextents = ip->di_anextents;
- printf(_("naextents 0x%lx forkoff %d dmevmask 0x%x dmstate 0x%hx\n"),
- nextents, (int)ip->di_forkoff, ip->di_dmevmask, ip->di_dmstate);
+ printf(_("naextents 0x%llx forkoff %d dmevmask 0x%x dmstate 0x%hx\n"),
+ (unsigned long long)nextents, (int)ip->di_forkoff, ip->di_dmevmask, ip->di_dmstate);
printf(_("flags 0x%x gen 0x%x\n"),
ip->di_flags, ip->di_gen);
if (ip->di_version == 3) {
diff --git a/repair/bmap.c b/repair/bmap.c
index 44e43ab4..cd1a8b07 100644
--- a/repair/bmap.c
+++ b/repair/bmap.c
@@ -38,10 +38,10 @@ blkmap_alloc(
#if (BITS_PER_LONG == 32) /* on 64-bit platforms this is never true */
if (nex > BLKMAP_NEXTS_MAX) {
do_warn(
- _("Number of extents requested in blkmap_alloc (%d) overflows 32 bits.\n"
+ _("Number of extents requested in blkmap_alloc (%llu) overflows 32 bits.\n"
"If this is not a corruption, then you will need a 64 bit system\n"
"to repair this filesystem.\n"),
- nex);
+ (unsigned long long)nex);
return NULL;
}
#endif
@@ -51,8 +51,8 @@ blkmap_alloc(
if (!blkmap || blkmap->naexts < nex) {
blkmap = realloc(blkmap, BLKMAP_SIZE(nex));
if (!blkmap) {
- do_warn(_("malloc failed in blkmap_alloc (%zu bytes)\n"),
- BLKMAP_SIZE(nex));
+ do_warn(_("malloc failed in blkmap_alloc (%llu bytes)\n"),
+ (unsigned long long)BLKMAP_SIZE(nex));
return NULL;
}
pthread_setspecific(key, blkmap);