Skip to content

Commit 1e0b871

Browse files
lemenkovrazvancrainea
authored andcommitted
Fix format specifier warnings on 32-bit architectures (i686) (#3791)
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) Assisted-by: Claude (Anthropic) <https://claude.ai> Signed-off-by: Peter Lemenkov <lemenkov@gmail.com> (cherry picked from commit 672e4dd)
1 parent 88b5343 commit 1e0b871

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

modules/aaa_diameter/dm_impl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <freeDiameter/extension.h>
2222
#include <sys/eventfd.h>
23+
#include <inttypes.h>
2324

2425
#include "../../ut.h"
2526
#include "../../lib/list.h"
@@ -485,7 +486,7 @@ static int dm_avps2json(void *root, cJSON *avps)
485486
break;
486487

487488
case AVP_TYPE_INTEGER64:
488-
LM_DBG("%2d. got int64 AVP %s (%u), value: %ld\n", i, dm_avp.avp_name, h->avp_code, h->avp_value->i64);
489+
LM_DBG("%2d. got int64 AVP %s (%u), value: %" PRId64 "\n", i, dm_avp.avp_name, h->avp_code, h->avp_value->i64);
489490
num_val = (double)h->avp_value->i64;
490491
break;
491492

@@ -495,7 +496,7 @@ static int dm_avps2json(void *root, cJSON *avps)
495496
break;
496497

497498
case AVP_TYPE_UNSIGNED64:
498-
LM_DBG("%2d. got uint64 AVP %s (%u), value: %lu\n", i, dm_avp.avp_name, h->avp_code, h->avp_value->u64);
499+
LM_DBG("%2d. got uint64 AVP %s (%u), value: %" PRIu64 "\n", i, dm_avp.avp_name, h->avp_code, h->avp_value->u64);
499500
num_val = (double)h->avp_value->u64;
500501
break;
501502

modules/http2d/server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ static int on_frame_recv_callback(nghttp2_session *session,
635635
switch (frame->hd.type) {
636636
case NGHTTP2_DATA:
637637
case NGHTTP2_HEADERS:
638-
LM_DBG("h2 header [%d], %p %ld\n", frame->hd.type, frame->headers.nva, frame->headers.nvlen);
638+
LM_DBG("h2 header [%d], %p %zu\n", frame->hd.type, frame->headers.nva, frame->headers.nvlen);
639639
/* Check that the client request has finished */
640640
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
641641
stream_data =

0 commit comments

Comments
 (0)