From aaa9cc0ed52c379e4dc6006bb26520811be53e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Wed, 2 Jan 2019 09:37:48 -0500 Subject: [PATCH 1/4] block, json, log: fix different signedness comparisons This fixes 2 comparisons between different signedness integers. The first one is the signal type defined in block structure. In C, signal numbers are defined as int. This commit fixes the definition in block.h. The second one is a comparison between and int and an enum. The comparison requires the enum to be caseted in int. The third one is the comparison between the result of snprintf()(ie. int) and a sizeof variable (ie. size_t). This comparison requires the int to be casted in unsigned, since the if statement ensures that the value is not negative. This commit casts the int variable in size_t when it is compared to a size_t. --- block.c | 2 +- block.h | 2 +- json.c | 2 +- log.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index af71b244..87614f0f 100644 --- a/block.c +++ b/block.c @@ -584,7 +584,7 @@ void block_printf(struct block *block, int lvl, const char *fmt, ...) va_list ap; int err; - if (lvl > log_level) + if (lvl > (int)log_level) return; va_start(ap, fmt); diff --git a/block.h b/block.h index a43816cc..abed98d4 100644 --- a/block.h +++ b/block.h @@ -50,7 +50,7 @@ struct block { /* Shortcuts */ const char *command; int interval; - unsigned signal; + int signal; unsigned format; /* Runtime info */ diff --git a/json.c b/json.c index 8f84130d..723b91f6 100644 --- a/json.c +++ b/json.c @@ -452,7 +452,7 @@ int json_escape(const char *str, char *buf, size_t size) } /* Ensure the result was not truncated */ - if (len < 0 || len >= size) + if (len < 0 || (size_t)len >= size) return -ENOSPC; size -= len; diff --git a/log.h b/log.h index a1ef2858..42ce7221 100644 --- a/log.h +++ b/log.h @@ -40,7 +40,7 @@ static inline void log_printf(int lvl, const char *fmt, ...) { va_list ap; - if (lvl <= LOG_ERROR || lvl <= log_level) { + if (lvl <= LOG_ERROR || lvl <= (int)log_level) { va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); From 341d4f353db4de507918d64099c893f19c723a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Wed, 2 Jan 2019 09:26:22 -0500 Subject: [PATCH 2/4] block: remove unused variable err The variable err is unused in functions block_send and block_setup. --- block.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/block.c b/block.c index 87614f0f..19de51dc 100644 --- a/block.c +++ b/block.c @@ -182,7 +182,6 @@ static int block_send_json(struct block *block) static int block_send(struct block *block) { const char *button = block_get(block, "button"); - int err; if (!button) { block_error(block, "no click data to send"); @@ -482,7 +481,6 @@ int block_reap(struct block *block) static int i3blocks_setup(struct block *block) { const char *value; - int err; value = map_get(block->config, "command"); if (value && *value != '\0') From 17d9b60905df0d64792002d4deaa11606103d026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Wed, 10 Jul 2019 13:08:37 -0400 Subject: [PATCH 3/4] block, ini, json: fix unused parameter This fixes several unused parameters using the common method: (void)the_unused_parameter; --- block.c | 6 ++++++ ini.c | 2 ++ json.c | 2 ++ 3 files changed, 10 insertions(+) diff --git a/block.c b/block.c index 19de51dc..a7e999d9 100644 --- a/block.c +++ b/block.c @@ -60,6 +60,8 @@ static int block_setenv(const char *name, const char *value, void *data) { int err; + (void)data; + if (!value) value = ""; @@ -216,6 +218,8 @@ void block_touch(struct block *block) unsigned long now; int err; + (void)block; + err = sys_gettime(&now); if (err) { block_error(block, "failed to touch block"); @@ -235,6 +239,8 @@ static int block_child_sig(struct block *block) sigset_t set; int err; + (void)block; + /* It'd be safe to assume that all signals are unblocked by default */ err = sys_sigfillset(&set); if (err) diff --git a/ini.c b/ini.c index 4a494ff4..7e984541 100644 --- a/ini.c +++ b/ini.c @@ -47,6 +47,8 @@ static int ini_property(struct ini *ini, char *key, char *value) static int ini_parse_line(char *line, size_t num, void *data) { + (void)num; + /* comment or empty line? */ if (*line == '\0' || *line == '#') return 0; diff --git a/json.c b/json.c index 723b91f6..65b4ca88 100644 --- a/json.c +++ b/json.c @@ -347,6 +347,8 @@ static int json_line_cb(char *line, size_t num, void *data) size_t len; int err; + (void)num; + for (;;) { /* Only support inline flattened structures at the moment */ while (*line == '[' || *line == ']' || *line == ',' || From 4163bd4a086a6e61bffd3ca67aca6dd89c6da610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Wed, 10 Jul 2019 13:17:55 -0400 Subject: [PATCH 4/4] autotools: compile against -Wall -Wextra and -Werror --- Makefile.am | 1 + configure.ac | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 2c91d7cb..5fa37703 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,3 +20,4 @@ i3blocks_SOURCES = \ sys.c \ sys.h \ term.h +i3blocks_CFLAGS = -Wall -Wextra -Werror $(AM_CFLAGS) diff --git a/configure.ac b/configure.ac index 1856185d..c3cc6218 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_INIT([i3blocks], 1.4) AC_CONFIG_AUX_DIR([build-aux]) -AM_INIT_AUTOMAKE(foreign) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_PROG_CC AC_CONFIG_HEADERS([i3blocks-config.h]) AC_CONFIG_FILES([