-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
gtls: fix build when sizeof(long) < sizeof(void *) #1617
Conversation
This issue came up while working on #1601. |
Coverage increased (+0.01%) to 73.823% when pulling 8a561d144d30e70f736db4653a7cba8279f77db1 on dscho:fix-gnutls-build into 922f800 on curl:master. |
unfortunately we don't have intptr_t in c89. we could use ptrdiff_t which is not technically correct since it's only meant to hold the difference between two members of the same array. it seems like casting between (gnutls_transport_ptr) would make more sense but it looks like those macros were added to fix the warning that comes from doing that. /cc @gknauf |
Good point.
I took this idea a little further: if we pretend that we have a hypothetical character array starting at The patch was updated accordingly. I verified that this fixes the compiler warning on Windows. |
Coverage increased (+0.008%) to 73.819% when pulling d98824ea819b511b1d5b88f5254770faf073d2f0 on dscho:fix-gnutls-build into 922f800 on curl:master. |
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.
It is a bit funny-looking, but should not cause any troubles as long as the result actually fits in 32 bits... And also, it was made funny before this patch.
@jay any objection? |
No. It seems like it's UB either way. To touch on what you said about 32 bits I think it could be improved if we rename them socket macros and cast to curl_socket_t since that's the type. Barring input from @gknauf how about these modifications to @dscho's work https://github.com/curl/curl/compare/master...jay:pr_1617_amended?expand=1 . I'm not sure if it would resurrect the warnings though |
I like that. Also, the underlying socket type on win64 ( |
@jay sadly, this does not work:
|
- Change gnutls pointer/int macros to pointer/curl_socket_t. Prior to this change they used long type as well. The size of the `long` data type can be shorter than that of pointer types. This is the case most notably on Windows. If C99 were acceptable, we could simply use `intptr_t` here. But we want to retain C89 compatibility. Simply use the trick of performing pointer arithmetic with the NULL pointer: to convert an integer `i` to a pointer, simply take the address of the `i`th element of a hypothetical character array starting at address NULL. To convert back, simply cast the pointer difference. Thanks to Jay Satiro for the initial modification to use curl_socket_t instead of int/long. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
I fixed that build error and amended jay@537b26c accordingly, force-pushing to the branch (and hence updating this PR). Good to go? |
👍 let's just first see that the CI doesn't find something unexpected |
Of course! ;-) |
Thanks! |
Everything seems to pass ;-) |
Oh, I missed that you closed this already. Sorry! |
This is the case most notably on Windows.
Signed-off-by: Johannes Schindelin johannes.schindelin@gmx.de