-
-
Notifications
You must be signed in to change notification settings - Fork 7k
urldata: switch to uint* types more widely #20209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
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 converts various integer types in lib/urldata.h and related files from platform-dependent types (unsigned long, unsigned int, unsigned char, unsigned short) to fixed-width integer types (uint32_t, uint16_t, uint8_t). This improves portability across platforms, particularly Windows where long is 32 bits, and reduces the size of the Curl_easy struct by 56 bytes on 64-bit Linux.
- Replaced platform-dependent unsigned types with fixed-width integer types
- Added explicit casts in setopt.c to handle type conversions
- Updated function signatures in http.c for consistency
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/urldata.h | Converted struct member types from unsigned long/int/short/char to fixed-width types (uint32_t, uint16_t, uint8_t) across multiple structs including ssl_primary_config, Curl_handler, connectdata, PureInfo, auth, UrlState, UserDefined, and Curl_easy |
| lib/setopt.c | Added explicit casts to uint32_t when assigning authentication values to proxyauth and httpauth fields |
| lib/http.c | Updated function parameter types from unsigned long * to uint32_t * in authentication-related functions (auth_spnego, auth_ntlm, auth_digest, auth_basic, auth_bearer) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Analysis of PR #20209 at f5499a4c: Test 3035 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Generated by Testclutch |
|
With a rebase it'll now run on DJGPP for an extra test. |
f5499a4 to
5da0147
Compare
I think I'm going to file a complaint on this. This is an |
With this I mean that I don't think we should fix this with using a define that changes I think changing %u to a define reduces readability for an edge case crazy compiler. |
I don't know. I also found it odd that it's only DJGPP complaining. My understanding is that for It didn't occur to me this is a DJGPP bug. It also picked other (non-printf) Seems legit to me, after all, it's not guaranteed that |
We use our own printf() code. We know it works with 32 bit fields for |
|
I think a much better take is to disable this warning when djgpp is used. |
It's kind of impossible to predict these, sorry. I spent my entire day fixing this, Super annoying indeed. Though I think the warning is correct, and DJGPP isn't supposed to know about DJGPP also caught non-printf cases, unrelated to curl's printf. edit: FTR, I personally don't use or care for MS-DOS, but until curl is supporting |
The printf() warnings have traditionally been useful since they detect mistakes and they do this because our printf() implementation is close enough to POSIX. In these cases, the warnings are quite clearly not correct for our code. We know this because we can read the printf() implementation. We also know this because we can use this code on countless platforms and even on MS-DOS without using PRIu32. These are pointless warnings that add nothing for us.
I'm again focusing on curl production code and there we always use our printf() code. And sure, if we use some other printf() somewhere else, that is another story. |
|
Using uint32_t is much kinder when dealing with multi-platform and multi-memory model compilation, IMO. |
In particular, it turns 'unsigned long' into 'uint32_t' since the code needs to build and run just as fine on Windows which has 32 bit longs, so we know the code works with 32 bit field versions. This makes Curl_easy 56 bytes smaller on my 64 bit Linux (maximized build).
5da0147 to
4bd448e
Compare
| unsigned int creds_from:2; /* where is the server credentials originating | ||
| from, see the CREDS_* defines above */ | ||
| uint32_t creds_from:2; /* where is the server credentials originating from, | ||
| see the CREDS_* defines above */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On OS400:
/home/MONNERAT/curl/lib/urldata.h, 1083.12: CZM0009(30) Bit field creds_from must be of type signed int, unsigned int
uint32_t field breaks compilation: it obviously is not an int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: IBM C header file stdint.h defines:
#ifndef _UINT32_T
#define _UINT32_T
typedef unsigned long uint32_t;
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, bitfields should not be done like that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-)
Thanks for your quick reaction
Bug: #20209 (review) Reported-by: Patrick Monnerat Follow-up to e369161
Bug: #20209 (review) Reported-by: Patrick Monnerat Follow-up to e369161 Closes #20244
In particular, it turns 'unsigned long' into 'uint32_t' since the code needs to build and run just as fine on Windows which has 32 bit longs, so we know the code works with 32 bit field versions.
This makes Curl_easy 56 bytes smaller on my 64 bit Linux (maximized build).