Skip to content

Commit 14b6d36

Browse files
Fix suspiscious logical construction
In code we find this flag: #define SOCK_BOUND_UDP 0x00040000 and test of this flag in socket state: if(pss->sockState & SOCK_BOUND_UDP) We also find the negation: if(!pss->sockState & SOCK_BOUND_UDP) But there is a precedenc eproblem in above expression, as reported by the compiler ../../platforms/win32/plugins/SocketPlugin/sqWin32NewNet.c:872:8: warning: logical not is only applied to the left hand side of this bitwise operator [-Wlogical-not-parentheses] if(!pss->sockState & SOCK_BOUND_UDP) { ^ ~ ../../platforms/win32/plugins/SocketPlugin/sqWin32NewNet.c:872:8: note: add parentheses after the '!' to evaluate the bitwise operator first if(!pss->sockState & SOCK_BOUND_UDP) { ^ ( ) ../../platforms/win32/plugins/SocketPlugin/sqWin32NewNet.c:872:8: note: add parentheses around left hand side expression to silence this warning if(!pss->sockState & SOCK_BOUND_UDP) { ^ ( ) Above code is interpreted as `if( (!pss->sockState) & SOCK_BOUND_UDP)` which does not mean much... Please, read C compiler warnings, they are a companion tool !
1 parent 32c4b79 commit 14b6d36

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

platforms/win32/plugins/SocketPlugin/sqWin32NewNet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ void sqSocketConnectToPort(SocketPtr s, sqInt addr, sqInt port)
869869
ADDRESS(s)->sin_addr.s_addr = htonl(addr);
870870

871871
if(TCPSocketType != s->socketType) { /* UDP/RAW */
872-
if(!pss->sockState & SOCK_BOUND_UDP) {
872+
if(!(pss->sockState & SOCK_BOUND_UDP)) {
873873
/* The socket is locally unbound and we
874874
must 'magically' assign a local port so
875875
that client code can also read from the socket */
@@ -2513,7 +2513,7 @@ void sqSocketConnectToAddressSize(SocketPtr s, char *addr, sqInt addrSize)
25132513
FAIL();
25142514

25152515
if(UDPSocketType == s->socketType) { /* UDP */
2516-
if(!pss->sockState & SOCK_BOUND_UDP) {
2516+
if(!(pss->sockState & SOCK_BOUND_UDP)) {
25172517
/* The socket is locally unbound and we
25182518
must 'magically' assign a local port so
25192519
that client code can also read from the socket */

0 commit comments

Comments
 (0)