Skip to content

Fix format specifier mismatches on 32-bit builds#301

Open
siraben wants to merge 5 commits intorhboot:mainfrom
siraben:fix-esl-iter-32bit-format-specifiers
Open

Fix format specifier mismatches on 32-bit builds#301
siraben wants to merge 5 commits intorhboot:mainfrom
siraben:fix-esl-iter-32bit-format-specifiers

Conversation

@siraben
Copy link
Copy Markdown

@siraben siraben commented Apr 19, 2026

Building on i686 glibc produces -Wformat warnings (and -Werror build
failures) from format strings using %lu/%ld/%lx/%zd with size_t,
off_t, and uint64_t arguments. These work on LP64 where long is
64-bit but break elsewhere.

Fixes are split per file/class: esl-iter.c (the bulk), secdb,
efivarfs, and efivar/efisecdb. %zu/%jd/%jx with appropriate
casts, plus PRIu64 where inttypes.h macros fit the surrounding style.

siraben added 5 commits April 19, 2026 13:27
On 32-bit platforms size_t and off_t aren't unsigned long, so the
debug() and warnx() calls in esl_list_iter_next_with_size_correction()
that used %lu, %ld, %zd, and %lx were mismatched to their arguments.
This produces -Wformat warnings on 32-bit builds, and is undefined
behavior under varargs.

Switch to %zu for size_t (with explicit (size_t) casts where the
expression's type was otherwise implementation-defined) and to %jd/%jx
with (intmax_t)/(uintmax_t) casts for off_t, which works regardless of
whether off_t is 32- or 64-bit.

Signed-off-by: Ben Siraphob <bensiraphob@gmail.com>
The ((intptr_t)iter->buf + (unsigned long)iter->offset) cast dance in
esl_list_iter_next_with_size_correction() is equivalent to plain
pointer arithmetic on iter->buf with (size_t)iter->offset, and avoids
the unsigned long cast which isn't portable for off_t on 32-bit.

Signed-off-by: Ben Siraphob <bensiraphob@gmail.com>
The debug() prints for datasz and sz mixed %zd with %lx.  On 32-bit
glibc size_t is unsigned int, not unsigned long, so %lx is mismatched
and produces -Wformat warnings.  And size_t is unsigned regardless, so
%zd is wrong for the decimal form too.

Use %zu for the decimal form and %zx for the hex form.

Signed-off-by: Ben Siraphob <bensiraphob@gmail.com>
The "Filepath too big" and "Filename too big" fprintf()s used %ld for
a size_t argument.  On 32-bit this doesn't match, and size_t is
unsigned regardless.

Signed-off-by: Ben Siraphob <bensiraphob@gmail.com>
The debug() prints of efi_n_well_known_guids, which is uint64_t, used
%lu.  On 32-bit unsigned long is 32-bit, so this mismatches the
argument.

Use the PRIu64 macro from inttypes.h, consistent with other 64-bit
prints elsewhere in the codebase (dp-hw.c, dp-media.c, etc.).

Signed-off-by: Ben Siraphob <bensiraphob@gmail.com>
@siraben siraben force-pushed the fix-esl-iter-32bit-format-specifiers branch from f460ab4 to 153bacc Compare April 19, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant