Fix format specifier mismatches on 32-bit builds#301
Open
siraben wants to merge 5 commits intorhboot:mainfrom
Open
Fix format specifier mismatches on 32-bit builds#301siraben wants to merge 5 commits intorhboot:mainfrom
siraben wants to merge 5 commits intorhboot:mainfrom
Conversation
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>
f460ab4 to
153bacc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Building on i686 glibc produces
-Wformatwarnings (and-Werrorbuildfailures) from format strings using
%lu/%ld/%lx/%zdwithsize_t,off_t, anduint64_targuments. These work on LP64 wherelongis64-bit but break elsewhere.
Fixes are split per file/class:
esl-iter.c(the bulk),secdb,efivarfs, andefivar/efisecdb.%zu/%jd/%jxwith appropriatecasts, plus
PRIu64whereinttypes.hmacros fit the surrounding style.