Fix miniupnpc setsockopt incompatible pointer type on Windows with GCC 14+#2542
Open
skypher wants to merge 1 commit intozerotier:devfrom
Open
Fix miniupnpc setsockopt incompatible pointer type on Windows with GCC 14+#2542skypher wants to merge 1 commit intozerotier:devfrom
skypher wants to merge 1 commit intozerotier:devfrom
Conversation
…C 14+
GCC 14+ treats -Wincompatible-pointer-types as an error by default.
On Windows, setsockopt() expects const char* for the option value, and
socket timeouts (SO_RCVTIMEO/SO_SNDTIMEO) use DWORD (milliseconds)
instead of struct timeval.
This was also a latent bug: the original code passed a struct timeval
(8 bytes: {tv_sec=3, tv_usec=0}) but Windows expects a DWORD (4 bytes)
containing milliseconds. Windows would read only the first 4 bytes
(value 3) as 3 milliseconds instead of the intended 3 seconds.
Open
2 tasks
Author
|
The fix has already been merged in upstream miniupnp: |
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
GCC 14+ treats
-Wincompatible-pointer-typesas an error by default. On Windows,setsockopt()expectsconst char*for the option value, and socket timeouts (SO_RCVTIMEO/SO_SNDTIMEO) useDWORD(milliseconds) instead ofstruct timeval.This PR fixes the miniupnpc
connecthostport.cto use the correct types on Windows:DWORDinstead ofstruct timevalfor the timeout variable(const char *)when callingsetsockopt()Note: This was a latent bug
The original code was actually broken on Windows, not just a type mismatch. The code passed a
struct timeval(8 bytes:{tv_sec=3, tv_usec=0}) but Windows expects aDWORD(4 bytes) containing milliseconds.Windows would read only the first 4 bytes (value
3) as 3 milliseconds instead of the intended 3 seconds. The code appeared to work because connections usually succeeded before the tiny 3ms timeout kicked in, and older GCC versions only warned about the pointer type mismatch rather than erroring.Test plan