]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Silence MINGW warning about INVALID_SOCKET
authorMilan Broz <gmazyland@gmail.com>
Fri, 27 Mar 2026 09:40:35 +0000 (10:40 +0100)
committerEugene Syromiatnikov <esyr@openssl.org>
Tue, 31 Mar 2026 00:21:33 +0000 (02:21 +0200)
On Windows, SOCKET is defined as unsigned (UINT_PTR).

In OpenSSL, the socket abstraction uses int, see
discussion in https://github.com/openssl/openssl/issues/7282.

MINGW for some time uses a signed definition of INVALID_SOCKET,
then switched back to unsigned, see for example
https://sourceforge.net/p/mingw-w64/discussion/723797/thread/71522d10/
Currently, it is defined as unsigned, creating many warnings like

  warning: overflow in conversion from 'long long unsigned int' to 'int'
  changes value from '18446744073709551615' to '-1' [-Woverflow]
  *sock = INVALID_SOCKET;

As we use INVALID_SOCKET only in our code, we can safely silence
this warning just by redefining INVALID_SOCKET to signed
(version that is commented out in MINGW headers).

While this is only a workaround, it has been here for years and
allows focus on more important warnings.

Signed-off-by: Milan Broz <gmazyland@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
MergeDate: Tue Mar 31 00:22:27 2026
(Merged from https://github.com/openssl/openssl/pull/30616)

include/internal/sockets.h

index c5f2978713c112fb5cc8d853c4365a379e44ba1f..ba8432c0a57c0203abdf77df1999c2f5f83571e6 100644 (file)
@@ -73,6 +73,15 @@ struct servent *PASCAL getservbyname(const char *, const char *);
 #define SHUT_RDWR SD_BOTH
 #endif
 
+/*
+ * Recent MINGW versions use Windows-style unsigned INVALID_SOCKET.
+ * Since OpenSSL uses int, this only silences an already-ignored warning.
+ */
+#if defined(__MINGW32__) && defined(INVALID_SOCKET)
+#undef INVALID_SOCKET
+#define INVALID_SOCKET (INT_PTR)(~0)
+#endif
+
 #else
 #if defined(__APPLE__)
 /*