Menu

#278 Don't check if a socket is < 0

2.0.2.0
closed
None
2019-10-21
2019-09-10
No

Don't check for a socket error by using the comparison < 0 in common or windows code. It is not working under windows where a socket is of a unsigned data type.

From Microsoft doc:
"Because the SOCKET type is unsigned, compiling existing source code from, for example, a UNIX environment may lead to compiler warnings about signed/unsigned data type mismatches.
This means, for example, that checking for errors when the socket and accept functions return should not be done by comparing the return value with –1, or seeing if the value is negative (both common and legal approaches in UNIX). Instead, an application should use the manifest constant INVALID_SOCKET as defined in the Winsock2.hheader file."

I have found two places where this is a problem.
Revision 2080
vos\windows\vos_sock.c line 1413
common\trdp_mdcom.c line 2704

Suggested solution:
Compare socket with VOS_INVALID_SOCKET

Discussion

  • Bernd Löhr

    Bernd Löhr - 2019-10-10
    • status: open --> accepted
    • assigned_to: Bernd Löhr
     
  • Bernd Löhr

    Bernd Löhr - 2019-10-10
    • status: accepted --> pending
     
  • Bernd Löhr

    Bernd Löhr - 2019-10-21
    • Status: pending --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB