This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] fix warnings in sys/select.h fortification with -Wsign-conversion
- From: Mike Frysinger <vapier at gentoo dot org>
- To: libc-alpha at sourceware dot org
- Date: Fri, 8 Jun 2012 18:50:17 -0400
- Subject: [PATCH] fix warnings in sys/select.h fortification with -Wsign-conversion
If we build code like so:
#include <sys/select.h>
int main(int argc, char *argv[])
{
int fd = argc;
fd_set fds;
FD_ZERO(&fds);
FD_SET(fd, &fds);
return argv[0][fd];
}
with warning flags like so:
$ gcc test.c -c -Wsign-conversion -O2 -Werror -D_FORTIFY_SOURCE=2
the build fails like so:
error: conversion to 'long unsigned int' from 'int' may change
the sign of the result [-Werror=sign-conversion]
This is because the fortification code is casting the signed fd up to
a signed value. If the fd is actually negative, the following check
in the code will catch it and warn.
So add an explicit cast to avoid the warning.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-06-08 Mike Frysinger <vapier@gentoo.org>
* misc/bits/select2.h (__FD_ELT): Cast d to unsigned long int.
---
misc/bits/select2.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/misc/bits/select2.h b/misc/bits/select2.h
index 9679925..cae144d 100644
--- a/misc/bits/select2.h
+++ b/misc/bits/select2.h
@@ -27,7 +27,7 @@ extern unsigned long int __fdelt_warn (unsigned long int __d)
#undef __FD_ELT
#define __FD_ELT(d) \
__extension__ \
- ({ unsigned long int __d = (d); \
+ ({ unsigned long int __d = (unsigned long int) (d); \
(__builtin_constant_p (__d) \
? (__d >= __FD_SETSIZE \
? __fdelt_warn (__d) : (__d / __NFDBITS)) \
--
1.7.9.7