From 027333e56aeea20c486702ecfb9571ca45fd14f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sat, 19 Jul 2014 17:44:49 +0200 Subject: Fix some compiler warnings `-Weverything' seems to have found a few problems. Also enabled clang sanitizers by default. --- src/common.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index 96548d9..b3d5e1b 100644 --- a/src/common.c +++ b/src/common.c @@ -982,7 +982,11 @@ poller_timers_get_poll_timeout (struct poller_timers *self) return -1; int64_t timeout = self->info->when - poller_timers_get_current_time (); - return timeout >= 0 ? timeout : 0; + if (timeout <= 0) + return 0; + if (timeout > INT_MAX) + return INT_MAX; + return timeout; } #ifdef __linux__ @@ -994,7 +998,7 @@ poller_timers_get_poll_timeout (struct poller_timers *self) struct poller_info { int fd; ///< Our file descriptor - uint32_t events; ///< The events we registered + short events; ///< The poll() events we registered for poller_dispatcher_func dispatcher; ///< Event dispatcher void *user_data; ///< User data }; @@ -1074,10 +1078,10 @@ poller_ensure_space (struct poller *self) (self->info, sizeof *self->info, self->alloc); } -static int -poller_epoll_to_poll_events (int events) +static short +poller_epoll_to_poll_events (uint32_t events) { - int result = 0; + short result = 0; if (events & EPOLLIN) result |= POLLIN; if (events & EPOLLOUT) result |= POLLOUT; if (events & EPOLLERR) result |= POLLERR; @@ -1087,7 +1091,7 @@ poller_epoll_to_poll_events (int events) } static uint32_t -poller_poll_to_epoll_events (uint32_t events) +poller_poll_to_epoll_events (short events) { uint32_t result = 0; if (events & POLLIN) result |= EPOLLIN; @@ -1099,7 +1103,7 @@ poller_poll_to_epoll_events (uint32_t events) } static void -poller_set (struct poller *self, int fd, short int events, +poller_set (struct poller *self, int fd, short events, poller_dispatcher_func dispatcher, void *data) { ssize_t index = poller_find_by_fd (self, fd); @@ -1185,7 +1189,7 @@ poller_run (struct poller *self) struct pollfd pfd; pfd.fd = info->fd; pfd.revents = poller_epoll_to_poll_events (revents->events); - pfd.events = poller_epoll_to_poll_events (info->events); + pfd.events = info->events; self->dispatch_next++; info->dispatcher (&pfd, info->user_data); @@ -1255,7 +1259,7 @@ poller_ensure_space (struct poller *self) } static void -poller_set (struct poller *self, int fd, short int events, +poller_set (struct poller *self, int fd, short events, poller_dispatcher_func dispatcher, void *data) { ssize_t index = poller_find_by_fd (self, fd); -- cgit v1.2.3