Fix format specifier warnings on 32-bit architectures (i686) #3791
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.
Summary
Fix format specifier warnings on 32-bit architectures (i686) with GCC 15
Details
This PR fixes compilation warnings that appear on 32-bit architectures (i686) when using GCC 15. The warnings are caused by using incorrect format specifiers for
size_t,int64_t, anduint64_ttypes, which have different sizes on 32-bit vs 64-bit platforms.On x86_64,
size_tandint64_tare aliases forunsigned longandlong intrespectively, so%ldand%luwork fine. However, on i686 (32-bit):size_tisunsigned int(4 bytes), notunsigned longint64_tislong long int(8 bytes), notlong intuint64_tisunsigned long long int(8 bytes), notunsigned long intThis causes GCC to emit
-Wformatwarnings on 32-bit builds, as the format specifiers don't match the actual argument types.Affected modules:
%ldforsize_tin server.c%ld/%luforint64_t/uint64_tin dm_impl.cSolution
Replace architecture-specific format specifiers with portable C99 standard specifiers:
%zuforsize_t(defined in C99, works on all architectures)%" PRId64forint64_t(from<inttypes.h>, expands to correct specifier per platform)%" PRIu64foruint64_t(from<inttypes.h>, expands to correct specifier per platform)These portable specifiers automatically adapt to the platform:
%zu→ format asunsigned long,PRId64→"ld",PRIu64→"lu"%zu→ format asunsigned int,PRId64→"lld",PRIu64→"llu"Compatibility
No compatibility impact. This is purely a build-time fix that doesn't change runtime behavior or APIs. The same values are printed, just with correct format specifiers.
Closing issues
N/A