diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-09-23 22:45:55 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-09-23 22:45:55 -0400 |
commit | 9c8db0f804360325e37f032c56c46ef627d2aaf7 (patch) | |
tree | b41270caa2ab37509228528f4b69d0599412f5c2 /select.c | |
parent | 045eef4cdea75c12be49327f961d6d2002c105dd (diff) | |
download | libevent-9c8db0f804360325e37f032c56c46ef627d2aaf7.tar.gz |
Fix all warnings in the main codebase flagged by -Wsigned-compare
Remember, the code
int is_less_than(int a, unsigned b) {
return a < b;
}
is buggy, since the C integer promotion rules basically turn it into
int is_less_than(int a, unsigned b) {
return ((unsigned)a) < b;
}
and we really want something closer to
int is_less_than(int a, unsigned b) {
return a < 0 || ((unsigned)a) < b;
}
.
Suggested by an example from Ralph Castain
Diffstat (limited to 'select.c')
-rw-r--r-- | select.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -234,11 +234,14 @@ select_add(struct event_base *base, int fd, short old, short events, void *p) if (sop->event_fds < fd) { int fdsz = sop->event_fdsz; - if (fdsz < sizeof(fd_mask)) - fdsz = sizeof(fd_mask); + if (fdsz < (int)sizeof(fd_mask)) + fdsz = (int)sizeof(fd_mask); + /* In theory we should worry about overflow here. In + * reality, though, the highest fd on a unixy system will + * not overflow here. XXXX */ while (fdsz < - (howmany(fd + 1, NFDBITS) * sizeof(fd_mask))) + (int) (howmany(fd + 1, NFDBITS) * sizeof(fd_mask))) fdsz *= 2; if (fdsz != sop->event_fdsz) { |