Range check winsock2's socket() return value
commitf006fc9325443bd93d1429fd19d68109a2d73eea
authorOlly Betts <olly@survex.com>
Fri, 23 Mar 2018 22:10:11 +0000 (24 11:10 +1300)
committerOlly Betts <olly@survex.com>
Sun, 25 Mar 2018 22:14:19 +0000 (26 11:14 +1300)
tree48b16c95fc9f4b135ee20bb3c389e892d5fab3bd
parent27d635735fa7b3c6d06c6b71df415072de39d993
Range check winsock2's socket() return value

Winsock2's socket() returns the unsigned type SOCKET, which is a 32-bit
type for WIN32 and a 64-bit type for WIN64.

It seems we can always safely assign SOCKET to an int: failure is indicated
by INVALID_SOCKET which will cast to -1 as an int, and it seems in
practice that valid values all fit in 31-bits (and that we're not the
only code to assume this since it makes it much easier to write code
that deals with BSD sockets and winsock2's bastardised version of them)
so Microsoft are unlikely to arbitrarily change that).

But we should check and throw an exception rather than quietly mangling
the value.

See #738.
xapian-core/common/safesysselect.h
xapian-core/common/safesyssocket.h