Fix miniupnpc setsockopt incompatible pointer type on Windows with GCC 14+ #2542
+24
−0
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