This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Suppress sign-conversion warning from FD_SET
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: libc-alpha at sourceware dot org
- Cc: ppluzhnikov at google dot com, yunlian at google dot com
- Date: Fri, 25 May 2012 09:27:01 -0700 (PDT)
- Subject: [PATCH] Suppress sign-conversion warning from FD_SET
Greetings,
Using glibc-2.15 to compile this file:
#include <sys/select.h>
int foo(int fd) {
fd_set fds;
FD_SET(fd, &fds);
return FD_ISSET(fd, &fds);
}
with 'gcc -O2 -D_FORTIFY_SOURCE=2 -Werror=sign-conversion -c t.c', results in:
t.c: In function 'foo':
t.c:4: error: conversion to 'long unsigned int' from 'int' may change the sign of the result
t.c:5: error: conversion to 'long unsigned int' from 'int' may change the sign of the result
Attached trivial patch fixes that.
Thanks,
--
Paul Pluzhnikov
2012-05-25 Paul Pluzhnikov <ppluzhnikov@google.com>
* misc/bits/select2.h (__FD_ELT): Add cast to suppress warning.
diff --git a/misc/bits/select2.h b/misc/bits/select2.h
index 9679925..4a20e11 100644
--- a/misc/bits/select2.h
+++ b/misc/bits/select2.h
@@ -1,5 +1,5 @@
/* Checking macros for select functions.
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -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)) \