From 77117b1cd51a763ef4b6f0bcee6ce8755bc6070e Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 5 Aug 2015 09:42:11 +0200 Subject: [PATCH] Add some more warning checks, and fix the ones reported --- cmdline/check.c | 16 ++++++++-------- cmdline/fnmatch.c | 6 ++++++ cmdline/status.c | 6 +++--- configure.ac | 5 ++++- raid/tag.c | 4 ++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/cmdline/check.c b/cmdline/check.c index 5c6553c6..7d35b629 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -302,19 +302,19 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* logs the status */ for (j = 0; j < failed_count; ++j) { - const char* state; + const char* desc; const char* hash; const char* data; struct snapraid_block* block = failed[j].block; unsigned block_state = block_state_get(block); switch (block_state) { - case BLOCK_STATE_DELETED : state = "delete"; break; - case BLOCK_STATE_CHG : state = "change"; break; - case BLOCK_STATE_REP : state = "replace"; break; - case BLOCK_STATE_BLK : state = "block"; break; + case BLOCK_STATE_DELETED : desc = "delete"; break; + case BLOCK_STATE_CHG : desc = "change"; break; + case BLOCK_STATE_REP : desc = "replace"; break; + case BLOCK_STATE_BLK : desc = "block"; break; /* LCOV_EXCL_START */ - default : state = "unknown"; break; + default : desc = "unknown"; break; /* LCOV_EXCL_STOP */ } @@ -338,9 +338,9 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign disk = handle->disk->name; sub = block_file_get(block)->sub; - log_tag("entry:%u:%s:%s:%s:%s:%s:%u:\n", j, state, hash, data, disk, esc(sub), block_file_pos(block)); + log_tag("entry:%u:%s:%s:%s:%s:%s:%u:\n", j, desc, hash, data, disk, esc(sub), block_file_pos(block)); } else { - log_tag("entry:%u:%s:%s:%s:\n", j, state, hash, data); + log_tag("entry:%u:%s:%s:%s:\n", j, desc, hash, data); } } diff --git a/cmdline/fnmatch.c b/cmdline/fnmatch.c index 6ead39aa..073f0aa6 100644 --- a/cmdline/fnmatch.c +++ b/cmdline/fnmatch.c @@ -491,4 +491,10 @@ fnmatch (pattern, string, flags) #endif /* _LIBC or not __GNU_LIBRARY__. */ +#else + +/* avoid the warning: ISO C forbids an empty translation unit */ +extern int make_iso_compilers_happy; + #endif + diff --git a/cmdline/status.c b/cmdline/status.c index 366adb46..6060855f 100644 --- a/cmdline/status.c +++ b/cmdline/status.c @@ -112,7 +112,7 @@ int state_status(struct snapraid_state* state) for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) { struct snapraid_disk* disk = node_disk->data; tommy_node* node; - block_off_t i; + block_off_t j; unsigned disk_file_count = 0; unsigned disk_file_fragmented = 0; unsigned disk_extra_fragment = 0; @@ -139,8 +139,8 @@ int state_status(struct snapraid_state* state) fragmented = 0; prev_pos = file->blockvec[0].parity_pos; - for (i = 1; i < file->blockmax; ++i) { - block_off_t parity_pos = file->blockvec[i].parity_pos; + for (j = 1; j < file->blockmax; ++j) { + block_off_t parity_pos = file->blockvec[j].parity_pos; if (prev_pos + 1 != parity_pos) { fragmented = 1; ++extra_fragment; diff --git a/configure.ac b/configure.ac index 20953dec..34988231 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.65]) AC_INIT([snapraid], [8.1], [], [], [http://www.snapraid.it]) AM_INIT_AUTOMAKE([foreign no-dependencies subdir-objects]) AC_CONFIG_SRCDIR([cmdline/snapraid.c]) -AC_CONFIG_HEADER([config.h]) +AC_CONFIG_HEADERS([config.h]) AC_CANONICAL_HOST dnl Checks for programs. @@ -90,6 +90,9 @@ AC_C_BIGENDIAN dnl Checks for compiler AC_CHECK_CC_OPT([-Wall], CFLAGS="$CFLAGS -Wall", []) AC_CHECK_CC_OPT([-Wextra], CFLAGS="$CFLAGS -Wextra", []) +AC_CHECK_CC_OPT([-Wuninitialized], CFLAGS="$CFLAGS -Wuninitialized", []) +AC_CHECK_CC_OPT([-Wshadow], CFLAGS="$CFLAGS -Wshadow", []) +AC_CHECK_CC_OPT([-Wpadded], CFLAGS="$CFLAGS -Wpadded", []) dnl Checks for AS supporting the SSE2 instructions. AC_MSG_CHECKING([for sse2]) diff --git a/raid/tag.c b/raid/tag.c index 055f82a5..bfeefaad 100644 --- a/raid/tag.c +++ b/raid/tag.c @@ -16,7 +16,7 @@ static struct raid_func { const char *name; - void *p; + void (*p)(); } RAID_FUNC[] = { { "int8", raid_gen3_int8 }, { "int8", raid_gen4_int8 }, @@ -78,7 +78,7 @@ static struct raid_func { { 0, 0 } }; -static const char *raid_tag(void *func) +static const char *raid_tag(void (*func)()) { struct raid_func *i = RAID_FUNC;