Re: [Mingw-w64-public] [PATCH] headers: cast fd to SOCKET in macros

2023-11-25 Thread LIU Hao

在 2023/11/25 15:59, LIU Hao 写道:
I don't think the patch is necessary. Windows socket handles are represented as `UINT_PTR` instead 
of plain `int`. On 64-bit Windows, storing a socket handle into `int` might cause truncation and is 
not safe.

Also, please read this reply: 
https://github.com/openssl/openssl/issues/7282#issuecomment-430633656

Some people have conditional typedefs for socket types so they use `SOCKET` on Windows and there 
will be no such warning. Some others (like OpenSSL) always use `int` and save four bytes; while we 
can assume this usually just 'works', it will be necessary to cast socket handles back to `SOCKET` 
from `int` when using Windows socket APIs.





--
Best regards,
LIU Hao



OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] headers: cast fd to SOCKET in macros

2023-11-25 Thread LIU Hao

在 2023/11/25 7:56, Oleg Tolmatcev 写道:

Socket.cpp:762:5: warning: comparison of integers of different signs:
'SOCKET' (aka 'unsigned long long') and 'const s32' (aka 'const int')
[-Wsign-compare]
   762 | FD_SET(fd, _fds);
   | ^~
C:/msys64/clang64/include/psdk_inc/_fd_types.h:77:40: note: expanded
from macro 'FD_SET'
77 | if (((fd_set *)(set))->fd_array[__i] == (fd))
{ \
   |  ^   ~~

This happens because on Windows a socket is unsigned and on Linux it
is signed and this is cross platform code.


I don't think the patch is necessary. Windows socket handles are represented as `UINT_PTR` instead 
of plain `int`. On 64-bit Windows, storing a socket handle into `int` might cause truncation and is 
not safe.



--
Best regards,
LIU Hao



OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] [PATCH] headers: cast fd to SOCKET in macros

2023-11-24 Thread Oleg Tolmatcev
Hello,

this patch fixes warnings like this in Dolphin

Socket.cpp:762:5: warning: comparison of integers of different signs:
'SOCKET' (aka 'unsigned long long') and 'const s32' (aka 'const int')
[-Wsign-compare]
  762 | FD_SET(fd, _fds);
  | ^~
C:/msys64/clang64/include/psdk_inc/_fd_types.h:77:40: note: expanded
from macro 'FD_SET'
   77 | if (((fd_set *)(set))->fd_array[__i] == (fd))
{ \
  |  ^   ~~

This happens because on Windows a socket is unsigned and on Linux it
is signed and this is cross platform code.

Best regards
Oleg Tolmatcev
From be6cad960b6ffb22797756b9d82e34bd372959c2 Mon Sep 17 00:00:00 2001
From: Oleg Tolmatcev 
Date: Sat, 25 Nov 2023 00:41:31 +0100
Subject: [PATCH] headers: cast fd to SOCKET in macros

---
 mingw-w64-headers/include/psdk_inc/_fd_types.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mingw-w64-headers/include/psdk_inc/_fd_types.h 
b/mingw-w64-headers/include/psdk_inc/_fd_types.h
index e3a5da62..18dcbe49 100644
--- a/mingw-w64-headers/include/psdk_inc/_fd_types.h
+++ b/mingw-w64-headers/include/psdk_inc/_fd_types.h
@@ -39,7 +39,7 @@ int WINAPI __WSAFDIsSet(SOCKET,fd_set *);
   do { \
u_int __i;  \
for(__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) {\
-   if (((fd_set *)(set))->fd_array[__i] == fd) {   \
+   if (((fd_set *)(set))->fd_array[__i] == (SOCKET)(fd)) { \
while (__i < ((fd_set *)(set))->fd_count - 1) { \
((fd_set *)(set))->fd_array[__i] =  \
 ((fd_set *)(set))->fd_array[__i + 1];  \
@@ -74,13 +74,13 @@ int WINAPI __WSAFDIsSet(SOCKET,fd_set *);
   do { \
u_int __i;  \
for(__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) {\
-   if (((fd_set *)(set))->fd_array[__i] == (fd)) { \
+   if (((fd_set *)(set))->fd_array[__i] == (SOCKET)(fd)) { \
break;  \
}   \
}   \
if (__i == ((fd_set *)(set))->fd_count) {   \
if (((fd_set *)(set))->fd_count < FD_SETSIZE) { \
-   ((fd_set *)(set))->fd_array[__i] = (fd);\
+   ((fd_set *)(set))->fd_array[__i] = (SOCKET)(fd);\
((fd_set *)(set))->fd_count++;  \
}   \
}   \
@@ -91,7 +91,7 @@ int WINAPI __WSAFDIsSet(SOCKET,fd_set *);
   do { \
if (((fd_set *)(set))->fd_count < FD_SETSIZE)   \
((fd_set *)(set))->fd_array[((fd_set *)(set))->fd_count++] =\
-  (fd);\
+  (SOCKET)(fd);\
   } while(0)
 #endif /* _WINSOCK2API_ */
 #endif /* !FD_SET */
-- 
2.43.0.windows.1

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public