From 5dc436539400a78874b994630bf58f29d31fd3f9 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 17 Sep 2014 21:49:37 +0200 Subject: [PATCH] Removes some clang warnings. --- cmdline/dry.c | 4 +++- cmdline/sync.c | 10 +++++----- raid/memory.c | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmdline/dry.c b/cmdline/dry.c index 18b6b2b3..f7b2f316 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -175,7 +175,9 @@ void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t block_off_t blockmax; int ret; struct snapraid_parity parity[LEV_MAX]; - struct snapraid_parity* parity_ptr[LEV_MAX]; + /* the following initialization is to avoid clang warnings about */ + /* potential state->level change, that never happens */ + struct snapraid_parity* parity_ptr[LEV_MAX] = { 0 }; unsigned error; unsigned l; diff --git a/cmdline/sync.c b/cmdline/sync.c index 6ed8ea34..3e82e847 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -1021,15 +1021,15 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t data_off_t out_size; int ret; struct snapraid_parity parity[LEV_MAX]; - struct snapraid_parity* parity_ptr[LEV_MAX]; + /* the following initialization is to avoid clang warnings about */ + /* potential state->level change, that never happens */ + struct snapraid_parity* parity_ptr[LEV_MAX] = { 0 }; unsigned unrecoverable_error; unsigned l; - unsigned level; int skip_sync = 0; printf("Initializing...\n"); - level = state->level; blockmax = parity_size(state); size = blockmax * (data_off_t)state->block_size; loaded_size = state->loaded_paritymax * (data_off_t)state->block_size; @@ -1046,7 +1046,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t blockmax = blockstart + blockcount; } - for(l=0;llevel;++l) { /* create the file and open for writing */ parity_ptr[l] = &parity[l]; ret = parity_create(parity_ptr[l], state->parity_path[l], &out_size, state->file_mode); @@ -1112,7 +1112,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t } } - for(l=0;llevel;++l) { ret = parity_sync(parity_ptr[l]); if (ret == -1) { /* LCOV_EXCL_START */ diff --git a/raid/memory.c b/raid/memory.c index bb49ee1e..30c96e5f 100644 --- a/raid/memory.c +++ b/raid/memory.c @@ -40,6 +40,8 @@ void **raid_malloc_vector(int nd, int n, size_t size, void **freeptr) unsigned char *va; int i; + BUG_ON(n <= 0 || nd < 0); + v = malloc(n * sizeof(void *)); if (!v) return 0;