Skip to content

lib: sync printf masks with uint32_t types - #20200

Closed
vszakats wants to merge 3 commits into
curl:masterfrom
vszakats:priu
Closed

vszakats wants to merge 3 commits into
curl:masterfrom
vszakats:priu

Conversation

@vszakats

@vszakats vszakats commented Jan 6, 2026 •

Copy link
Copy Markdown
Member

Also adjust a printf mask for signedness.

Fixing with MS-DOS DJGPP gcc 12.2.0:

lib/conncache.c:612:22: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'}
lib/multi.c:394:22: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:520:20: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:520:20: error: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:611:20: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:614:22: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:887:20: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:887:20: error: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:2719:26: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:2725:30: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:2729:28: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:3126:34: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:3348:34: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi.c:3991:28: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi_ev.c:343:24: error: format '%u' expects argument of type 'unsigned int', but argument 6 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi_ev.c:413:24: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi_ev.c:584:36: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi_ntfy.c:113:34: error: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi_ntfy.c:113:34: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} 
lib/multi_ntfy.c:171:22: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} 
lib/url.c:883:22: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
lib/url.c:889:22: error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 

Bug: #20199 (comment)
Follow-up to 4c9e4e9 #20208


@vszakats vszakats added the build label Jan 6, 2026
@vszakats
vszakats marked this pull request as draft January 6, 2026 23:51
@vszakats
vszakats marked this pull request as ready for review January 7, 2026 00:50
@vszakats

vszakats commented Jan 7, 2026

Copy link
Copy Markdown
Member Author

augment review

@augmentcode

augmentcode Bot commented Jan 7, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR fixes printf-format mismatches where libcurl logs/infos print uint32_t values with %u/%d, which fails on platforms where uint32_t is not an unsigned int.

Changes:

  • Switches a number of `CURL_TRC_M()` and `infof()` format strings to use `PRIu32` for `uint32_t` fields (e.g., `mid`, `attached_xfers`, set/table counts).
  • Adds `` inclusion for `PRIu32` via `lib/curl_setup.h`.
  • Defines `PRIu32` for older MSVC versions (VS2010/VS2012) where `inttypes.h` may be missing/incomplete.
  • Adjusts one trace message to correct signedness when printing notification types.

Technical Notes: Addresses -Wformat errors reported with DJGPP (where uint32_t can be unsigned long).

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes printf format specifier warnings when compiling with MS-DOS DJGPP gcc 12.2.0, where uint32_t is long unsigned int rather than unsigned int. The fix replaces hardcoded %u and %d format specifiers with the portable PRIu32 macro for all uint32_t variables, and adds support for PRIu32 by including <inttypes.h> (with a manual definition for VS2010/VS2012 which lack this header).

Key Changes

  • Added <inttypes.h> include to lib/curl_setup.h with manual PRIu32 definition for VS2010/VS2012
  • Replaced %u and %d format specifiers with %" PRIu32 for all uint32_t variables across multiple files
  • Fixed one incorrect %d to PRIu32 conversion (should have been unsigned)

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/curl_setup.h Added <inttypes.h> include with VS2010/VS2012 fallback definition for PRIu32
lib/url.c Updated format specifiers for conn->attached_xfers (uint32_t)
lib/multi_ntfy.c Updated format specifiers for e->type, e->mid, and data->mid (all uint32_t), also fixed signedness issue
lib/multi_ev.c Updated format specifiers for various uint32_t counters and transfer IDs
lib/multi.c Updated format specifiers for mid, master_mid, attached_xfers, and various uint32_t table/set counts
lib/conncache.c Updated format specifier for conn->attached_xfers (uint32_t)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/curl_setup.h Resolved
@github-actions github-actions Bot added the CI Continuous Integration label Jan 7, 2026
@vszakats vszakats changed the title lib: sync printf masks with uint32_t types lib: sync printf masks with uint32_t types, restore HAVE_STDINT_H Jan 7, 2026
@vszakats vszakats changed the title lib: sync printf masks with uint32_t types, restore HAVE_STDINT_H lib: sync printf masks with uint32_t types, restore HAVE_INTTYPES_H Jan 7, 2026
@vszakats
vszakats requested a review from Copilot January 7, 2026 09:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/curl_setup.h
Comment on lines 461 to 471
#if defined(HAVE_STDINT_H) || defined(USE_WOLFSSL)
#include <stdint.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
#define PRIu32 "u"
#endif

#include <limits.h>

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback definition assumes uint32_t is the same type as unsigned int, which may not be true on all platforms. On systems where uint32_t is unsigned long (such as systems with 16-bit int), this will cause printf format mismatches. Consider using a platform-specific fallback that checks SIZEOF_INT or use "lu" for platforms where int is not 32 bits.

Suggested change
#if defined(HAVE_STDINT_H) || defined(USE_WOLFSSL)
#include <stdint.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
#define PRIu32 "u"
#endif
#include <limits.h>
#include <limits.h>
#if defined(HAVE_STDINT_H) || defined(USE_WOLFSSL)
#include <stdint.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
/* Fallback definition of PRIu32 when <inttypes.h> is unavailable.
Select the correct format specifier based on the width of the
standard unsigned integer types. */
# if defined(UINT_MAX) && (UINT_MAX == 0xFFFFFFFFU)
# define PRIu32 "u"
# elif defined(ULONG_MAX) && (ULONG_MAX == 0xFFFFFFFFUL)
# define PRIu32 "lu"
# else
/* Conservative fallback: assume 32-bit type maps to unsigned long. */
# define PRIu32 "lu"
# endif
#endif

Copilot uses AI. Check for mistakes.

@vszakats vszakats Jan 7, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but, I'd rather leave that to someone else, who can double-check this.

Shorter version of the above:

#if UINT_MAX == 0xFFFFFFFFU  /* or possibly compare to `ULONG_MAX`? */
#define PRIu32 "u"
#else
#define PRIu32 "lu"
#endif

FTR on DJGPP UINT_MAX and ULONG_MAX are both 4294967295U[L], and PRIu32 is lu, not matching the logic above.

vszakats added a commit that referenced this pull request Jan 7, 2026
For `PRI*` printf masks for fixed-size C99 types.

Also:
- add simple fallback for `PRIu32`, `PRIx32`, if `inttypes.h` is
  missing.

Cherry-picked from #20200
Ref: #20207
Follow-up to 4701a6d #19695
Ref: 60359ad #12275
Closes #20208
@vszakats vszakats changed the title lib: sync printf masks with uint32_t types, restore HAVE_INTTYPES_H lib: sync printf masks with uint32_t types Jan 7, 2026
@vszakats vszakats closed this in e70436a Jan 7, 2026
@vszakats
vszakats deleted the priu branch January 7, 2026 15:28
vszakats added a commit to vszakats/curl that referenced this pull request Jan 7, 2026
vszakats added a commit that referenced this pull request Jan 7, 2026
Fixes MS-DOS DJGPP buidls, possibly others.

Follow-up to e70436a #20200
Follow-up to 4701a6d #19695

Closes #20210
vszakats added a commit that referenced this pull request Jan 7, 2026
In `!ssl` variant.

It's useful to catch `uint32_t` mismatches with `unsigned int` or its
printf mask.

Also add Renovate version bump rule.

It takes about 1m (autotools) + 30s (cmake) in CI.

Bug: #20199 (comment)
Follow-up to 8881a52 #20210
Follow-up to e70436a #20200
Follow-up to 0630e66 #18338

Closes #20204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build CI Continuous Integration

Development

Successfully merging this pull request may close these issues.

2 participants