Closed sunfishcode closed 5 years ago
The use of size_t
is sort of intentional here.
POSIX added socklen_t
to introduce portability between systems that use int
(BSD & ...) and some that use size_t
(QNX & ...). In my opinion it is a moronic type that should not have existed; code should have used size_t
to begin with. You typically assign it to values obtained from sizeof()
. Negative values are simply impossible. This is why cloudlibc declares it as size_t
.
Even though cloudlibc declares socklen_t
, it doesn't use it anywhere:
$ git grep socklen_t
src/include/netdb.h:typedef __size_t socklen_t;
src/include/sys/socket.h:typedef __size_t socklen_t;
This is because none of the code in cloudlibc has been designed to deal with these types being anything other than size_t
. For example, it may well be the case that if socklen_t
would be redefined to be smaller than size_t
or become signed, we may run into bugs in functions that have socklen_t
parameters (e.g., missing bounds checking, negative array indexing). By simply using size_t
all over the place, we will cause explicit compiler errors if our assumptions would no longer hold.
Makes sense, thanks for the explanation!
This changes inet_ntop's size parameter from size_t to socklen_t, following POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html
In cloudlibc, these are typedefs for the same type, so there's no effective change here.