From 3878c0e2e652ea4e57a66b82617baf3f6a3d229e Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 30 Jul 2026 12:40:08 +0200 Subject: [PATCH] Silence clang static analyzer warnings --- Makefile.am | 1 + cmdline/check.c | 4 +++- cmdline/dry.c | 2 -- cmdline/handle.c | 2 +- cmdline/pool.c | 4 ++-- cmdline/scan.c | 3 +++ cmdline/unixapp.c | 2 ++ cmdline/util.c | 27 ++++++++++++++++----------- configure.analyzer | 1 + os/unix.c | 8 ++++++-- 10 files changed, 35 insertions(+), 19 deletions(-) create mode 100755 configure.analyzer diff --git a/Makefile.am b/Makefile.am index 5ca90827..64a159b5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -229,6 +229,7 @@ clean-local: rm -f lcov.info rm -f gmon.out rm -f makeslackware.sh makeslackdist.sh pkg/snapraid.SlackBuild pkg/snapraid.info makedeb.sh pkg/control makerpm.sh pkg/snapraid.spec + rm -fr *.plist maintainer-clean-local: rm -f $(LIST_MAN) diff --git a/cmdline/check.c b/cmdline/check.c index 17af6ce8..1a80e35e 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -329,7 +329,9 @@ static int repair(struct snapraid_state* state, int rehash, block_off_t pos, uns /* LCOV_EXCL_STOP */ } - if (hash_is_invalid(block->hash)) { + if (block == BLOCK_NULL) { + hash = "none"; + } else if (hash_is_invalid(block->hash)) { hash = "lost"; } else if (hash_is_zero(block->hash)) { hash = "zero"; diff --git a/cmdline/dry.c b/cmdline/dry.c index 04343764..c6bdaaf9 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -188,8 +188,6 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit /* start all the worker threads */ io_start(&io, blockstart, blockmax, 0); - blockcur = blockstart; - int alert = state_progress_begin(state, blockstart, blockmax, countmax); if (alert > 0) goto end; diff --git a/cmdline/handle.c b/cmdline/handle.c index 34bba9f3..3ebf9b63 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -136,7 +136,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int out_missing = log_error; /* if already opened, nothing to do */ - if (handle->file == file && handle->file != 0 && handle->f != -1) { + if (handle->file != 0 && handle->file == file && handle->f != -1) { return 0; } diff --git a/cmdline/pool.c b/cmdline/pool.c index 7027d59b..d3707d92 100644 --- a/cmdline/pool.c +++ b/cmdline/pool.c @@ -80,7 +80,7 @@ static int clean_dir(const char* dir) exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - if (dd == 0 && errno == 0) { + if (dd == 0) { break; /* finished */ } @@ -196,7 +196,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - if (dd == 0 && errno == 0) { + if (dd == 0) { break; /* finished */ } diff --git a/cmdline/scan.c b/cmdline/scan.c index 57a775b2..fa7b0be8 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -2007,7 +2007,10 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) int all_missing = 0; int all_rewritten = 0; done = 0; + for (i = state->disklist, j = scanlist; i != 0; i = i->next, j = j->next) { + assert(j != 0); /* silence the clang static analyzer (both lists have the same number of elements) */ + struct snapraid_disk* disk = i->data; struct snapraid_scan* scan = j->data; diff --git a/cmdline/unixapp.c b/cmdline/unixapp.c index ca0c03da..1c6889e0 100644 --- a/cmdline/unixapp.c +++ b/cmdline/unixapp.c @@ -2026,6 +2026,8 @@ int fssnapshot_mount(const char* path, struct fssnapshot_struct* fss) /* LCOV_EXCL_STOP */ } + assert(fss != 0); /* silence the clang static analyzer (it's never called with a NULL fss) */ + if (sfs.f_type == BTRFS_SUPER_MAGIC) { /* btrfs reserved inode 256 for subvolume roots */ return fssnapshot_inode(path, BTRFS_SUPER_MAGIC, 256, fss); diff --git a/cmdline/util.c b/cmdline/util.c index 021e2567..5a0572e9 100644 --- a/cmdline/util.c +++ b/cmdline/util.c @@ -457,30 +457,30 @@ void crc32c_init(void) /* * Rotate left. - * In x86/x64 they are optimized with a single assembler instruction. + * In x86/x64/ARM they are optimized with a single assembler instruction. */ -static inline uint32_t util_rotl32(uint32_t x, int8_t r) +static inline uint32_t util_rotl32(uint32_t x, unsigned r) { - return (x << r) | (x >> (32 - r)); + return (x << (r & 31)) | (x >> ((-r) & 31)); } -static inline uint64_t util_rotl64(uint64_t x, int8_t r) +static inline uint64_t util_rotl64(uint64_t x, unsigned r) { - return (x << r) | (x >> (64 - r)); + return (x << (r & 63)) | (x >> ((-r) & 63)); } /* * Rotate right. - * In x86/x64 they are optimized with a single assembler instruction. + * In x86/x64/ARM they are optimized with a single assembler instruction. */ -static inline uint32_t util_rotr32(uint32_t x, int8_t r) +static inline uint32_t util_rotr32(uint32_t x, unsigned r) { - return (x >> r) | (x << (32 - r)); + return (x >> (r & 31)) | (x << ((-r) & 31)); } -static inline uint64_t util_rotr64(uint64_t x, int8_t r) +static inline uint64_t util_rotr64(uint64_t x, unsigned r) { - return (x >> r) | (x << (64 - r)); + return (x >> (r & 63)) | (x << ((-r) & 63)); } /** @@ -677,24 +677,29 @@ int util_selftest(void) if (util_rotl32(0x00000001U, 31) != 0x80000000U) return -1; if (util_rotl32(0x12345678U, 4) != 0x23456781U) return -1; if (util_rotl32(0x12345678U, 0) != 0x12345678U) return -1; - if (util_rotl32(0x12345678U, 32) != 0x12345678U) return -1; /* r % 32 == 0 */ + if (util_rotl32(0x12345678U, 32) != 0x12345678U) return -1; /* rotate right 32-bit */ if (util_rotr32(0x00000001U, 1) != 0x80000000U) return -1; if (util_rotr32(0x80000000U, 1) != 0x40000000U) return -1; if (util_rotr32(0x00000002U, 1) != 0x00000001U) return -1; if (util_rotr32(0x12345678U, 4) != 0x81234567U) return -1; + if (util_rotr32(0x12345678U, 0) != 0x12345678U) return -1; + if (util_rotr32(0x12345678U, 32) != 0x12345678U) return -1; /* rotate left 64-bit */ if (util_rotl64(1ULL, 1) != 2ULL) return -1; if (util_rotl64(1ULL << 63, 1) != 1ULL) return -1; if (util_rotl64(0x123456789ABCDEF0ULL, 8) != 0x3456789ABCDEF012ULL) return -1; if (util_rotl64(0x123456789ABCDEF0ULL, 0) != 0x123456789ABCDEF0ULL) return -1; + if (util_rotl64(0x123456789ABCDEF0ULL, 64) != 0x123456789ABCDEF0ULL) return -1; /* rotate right 64-bit */ if (util_rotr64(1ULL, 1) != (1ULL << 63)) return -1; if (util_rotr64(2ULL, 1) != 1ULL) return -1; if (util_rotr64(0x123456789ABCDEF0ULL, 8) != 0xF0123456789ABCDEULL) return -1; + if (util_rotr64(0x123456789ABCDEF0ULL, 0) != 0x123456789ABCDEF0ULL) return -1; + if (util_rotr64(0x123456789ABCDEF0ULL, 64) != 0x123456789ABCDEF0ULL) return -1; /* util_mum tests */ uint64_t a, b; diff --git a/configure.analyzer b/configure.analyzer new file mode 100755 index 00000000..68cb0dc5 --- /dev/null +++ b/configure.analyzer @@ -0,0 +1 @@ +./configure CC=/usr/libexec/ccc-analyzer diff --git a/os/unix.c b/os/unix.c index 32466ae7..26797044 100644 --- a/os/unix.c +++ b/os/unix.c @@ -1592,8 +1592,8 @@ void os_abort(void) unsigned i; #endif - const char* platform = ""; - const char* compiler = ""; + const char* platform; + const char* compiler; #ifdef _linux platform = ", linux"; @@ -1601,12 +1601,16 @@ void os_abort(void) platform = ", macOS"; #elif defined(__FreeBSD__) platform = ", FreeBSD"; +#else + platform = ""; #endif #if defined(__clang__) compiler = ", clang " __clang_version__; #elif defined(__GNUC__) compiler = ", gcc " __VERSION__; +#else + compiler = ""; #endif os_syslog(OS_LVL_CRITICAL, "Stacktrace of " PACKAGE " v" VERSION