Fix format specifier warnings on 32-bit architectures (i686)#3791
Open
lemenkov wants to merge 1 commit intoOpenSIPS:masterfrom
Open
Fix format specifier warnings on 32-bit architectures (i686)#3791lemenkov wants to merge 1 commit intoOpenSIPS:masterfrom
lemenkov wants to merge 1 commit intoOpenSIPS:masterfrom
Conversation
During compilation on i686 (32-bit) architecture with GCC 15, format
specifier warnings appear due to type size differences between 32-bit
and 64-bit platforms.
```
server.c: In function 'on_frame_recv_callback':
warning: format '%ld' expects argument of type 'long int', but argument 14
has type 'size_t' {aka 'unsigned int'} [-Wformat=]
638 | LM_DBG("h2 header [%d], %p %ld\n", frame->hd.type, frame->headers.nva, frame->headers.nvlen);
dm_impl.c: In function 'dm_avps2json':
warning: format '%ld' expects argument of type 'long int', but argument 15
has type 'int64_t' {aka 'long long int'} [-Wformat=]
484 | LM_DBG("%2d. got int64 AVP %s (%u), value: %ld\n", i, dm_avp.avp_name, h->avp_code, h->avp_value->i64);
warning: format '%lu' expects argument of type 'long unsigned int', but argument 15
has type 'uint64_t' {aka 'long long unsigned int'} [-Wformat=]
494 | LM_DBG("%2d. got uint64 AVP %s (%u), value: %lu\n", i, dm_avp.avp_name, h->avp_code, h->avp_value->u64);
```
Type sizes differ between 32-bit and 64-bit architectures:
**On x86_64 (64-bit):**
- `size_t` = `unsigned long` (8 bytes)
- `int64_t` = `long int` (8 bytes)
**On i686 (32-bit):**
- `size_t` = `unsigned int` (4 bytes)
- `int64_t` = `long long int` (8 bytes)
- `uint64_t` = `unsigned long long int` (8 bytes)
Use portable C99 format specifiers that work correctly on all
architectures:
- `%zu` for `size_t` (modules/http2d/server.c line 638)
- `%" PRId64` for `int64_t` (modules/aaa_diameter/dm_impl.c line 484)
- `%" PRIu64` for `uint64_t` (modules/aaa_diameter/dm_impl.c line 494)
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
Assisted-by: Claude (Anthropic) <https://claude.ai>
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.
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