[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#739594: FD_SET / FD_ISSET warning: signed and unsigned type in conditional expression [-Wsign-compare]



Package: libc6-dev
Version: 2.17-96
Severity: wishlist

Enabling HARDENING_FLAGS enables -Wsign-compare, this results in:

warning: signed and unsigned type in conditional expression [-Wsign-compare]

for the FD_SET and FD_ISSET macro as the include file forces 'int'
computation on an array:

current macro:
#define __NFDBITS       (8 * (int) sizeof (__fd_mask))
#define FD_SET(fd, fdsetp)      __FD_SET (fd, fdsetp)

replace it with:
#define __NFDBITS       (8 * (unsigned int) sizeof (__fd_mask))
#define FD_SET(fd, fdsetp)      __FD_SET (((unsigned int)fd), fdsetp)

And everything is fine.

Changes to be made in:
/usr/include/x86_64-linux-gnu/sys/select.h

This might also be the case on i386 and similar platforms.

Note that filedescriptors (fd) are typically defined as 'int', hence the
cast to (unsigned int) for FD_SET to force that into alignment too.
(yep, calling FD_SET with a -1/negative FD will cause strange issues,
but you will get those anyway, and they should in theory get caught by
the stack protectors)

Greets,
 Jeroen


Reply to: