From 027333e56aeea20c486702ecfb9571ca45fd14f6 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch 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. --- Makefile | 3 ++- src/common.c | 22 +++++++++++++--------- src/kike.c | 8 ++++---- src/siphash.c | 3 ++- src/zyklonb.c | 8 ++++---- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 59be4bf..55b236a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ SHELL = /bin/sh CC = clang # -Wunused-function is pretty annoying here, as everything is static and not # all parts of common.c are used in all the executables -CFLAGS = -ggdb -Wall -Wextra -std=c99 -Wno-unused-function +CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-function \ + -ggdb -fsanitize=address,undefined # -lpthread is only there for debugging (gdb & errno) LDFLAGS = `pkg-config --libs libssl` -lpthread 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); diff --git a/src/kike.c b/src/kike.c index 1ca6b0c..1ae4cee 100644 --- a/src/kike.c +++ b/src/kike.c @@ -222,11 +222,11 @@ struct client struct str read_buffer; ///< Unprocessed input struct str write_buffer; ///< Output yet to be sent out - unsigned initialized : 1; ///< Has any data been received yet? - unsigned registered : 1; ///< The user has registered + bool initialized; ///< Has any data been received yet? + bool registered; ///< The user has registered - unsigned ssl_rx_want_tx : 1; ///< SSL_read() wants to write - unsigned ssl_tx_want_rx : 1; ///< SSL_write() wants to read + bool ssl_rx_want_tx; ///< SSL_read() wants to write + bool ssl_tx_want_rx; ///< SSL_write() wants to read SSL *ssl; ///< SSL connection char *nickname; ///< IRC nickname (main identifier) diff --git a/src/siphash.c b/src/siphash.c index 842af7d..7a5c8d4 100644 --- a/src/siphash.c +++ b/src/siphash.c @@ -52,7 +52,8 @@ siphash (const unsigned char key[16], const unsigned char *m, size_t len) v1 ^= v2; v3 ^= v0; \ v2 = ROTL64(v2,32); - for (i = 0, blocks = (len & ~7); i < blocks; i += 8) { + for (i = 0, blocks = (len & ~(size_t) 7); i < blocks; i += 8) + { mi = u8to64_le (m + i); v3 ^= mi; COMPRESS diff --git a/src/zyklonb.c b/src/zyklonb.c index e5e8749..ca579d1 100644 --- a/src/zyklonb.c +++ b/src/zyklonb.c @@ -55,8 +55,8 @@ struct plugin_data LIST_HEADER (plugin_data) struct bot_context *ctx; ///< Parent context - pid_t pid; ///< PID of the plugin process char *name; ///< Plugin identifier + pid_t pid; ///< PID of the plugin process bool is_zombie; ///< Whether the child is a zombie bool initialized; ///< Ready to exchange IRC messages @@ -66,9 +66,9 @@ struct plugin_data // we don't stall on plugins unnecessarily. int read_fd; ///< The read end of the comm. pipe - struct str read_buffer; ///< Unprocessed input - int write_fd; ///< The write end of the comm. pipe + + struct str read_buffer; ///< Unprocessed input struct str write_buffer; ///< Output yet to be sent out }; @@ -1610,7 +1610,7 @@ on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx) // "plugin `name' died like a dirty jewish pig"; use `status' if (!plugin->is_zombie && WIFSIGNALED (status)) { - char *notes = ""; + const char *notes = ""; #ifdef WCOREDUMP if (WCOREDUMP (status)) notes = " (core dumped)"; -- cgit v1.2.3-70-g09d2