Silence clang static analyzer warnings

This commit is contained in:
Andrea Mazzoleni 2026-07-30 12:40:08 +02:00
parent 76124cff00
commit 3878c0e2e6
10 changed files with 35 additions and 19 deletions

View file

@ -229,6 +229,7 @@ clean-local:
rm -f lcov.info rm -f lcov.info
rm -f gmon.out 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 -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: maintainer-clean-local:
rm -f $(LIST_MAN) rm -f $(LIST_MAN)

View file

@ -329,7 +329,9 @@ static int repair(struct snapraid_state* state, int rehash, block_off_t pos, uns
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
if (hash_is_invalid(block->hash)) { if (block == BLOCK_NULL) {
hash = "none";
} else if (hash_is_invalid(block->hash)) {
hash = "lost"; hash = "lost";
} else if (hash_is_zero(block->hash)) { } else if (hash_is_zero(block->hash)) {
hash = "zero"; hash = "zero";

View file

@ -188,8 +188,6 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit
/* start all the worker threads */ /* start all the worker threads */
io_start(&io, blockstart, blockmax, 0); io_start(&io, blockstart, blockmax, 0);
blockcur = blockstart;
int alert = state_progress_begin(state, blockstart, blockmax, countmax); int alert = state_progress_begin(state, blockstart, blockmax, countmax);
if (alert > 0) if (alert > 0)
goto end; goto end;

View file

@ -136,7 +136,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int
out_missing = log_error; out_missing = log_error;
/* if already opened, nothing to do */ /* 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; return 0;
} }

View file

@ -80,7 +80,7 @@ static int clean_dir(const char* dir)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
if (dd == 0 && errno == 0) { if (dd == 0) {
break; /* finished */ break; /* finished */
} }
@ -196,7 +196,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
if (dd == 0 && errno == 0) { if (dd == 0) {
break; /* finished */ break; /* finished */
} }

View file

@ -2007,7 +2007,10 @@ static int state_diffscan(struct snapraid_state* state, int is_diff)
int all_missing = 0; int all_missing = 0;
int all_rewritten = 0; int all_rewritten = 0;
done = 0; done = 0;
for (i = state->disklist, j = scanlist; i != 0; i = i->next, j = j->next) { 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_disk* disk = i->data;
struct snapraid_scan* scan = j->data; struct snapraid_scan* scan = j->data;

View file

@ -2026,6 +2026,8 @@ int fssnapshot_mount(const char* path, struct fssnapshot_struct* fss)
/* LCOV_EXCL_STOP */ /* 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) { if (sfs.f_type == BTRFS_SUPER_MAGIC) {
/* btrfs reserved inode 256 for subvolume roots */ /* btrfs reserved inode 256 for subvolume roots */
return fssnapshot_inode(path, BTRFS_SUPER_MAGIC, 256, fss); return fssnapshot_inode(path, BTRFS_SUPER_MAGIC, 256, fss);

View file

@ -457,30 +457,30 @@ void crc32c_init(void)
/* /*
* Rotate left. * 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. * 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(0x00000001U, 31) != 0x80000000U) return -1;
if (util_rotl32(0x12345678U, 4) != 0x23456781U) return -1; if (util_rotl32(0x12345678U, 4) != 0x23456781U) return -1;
if (util_rotl32(0x12345678U, 0) != 0x12345678U) 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 */ /* rotate right 32-bit */
if (util_rotr32(0x00000001U, 1) != 0x80000000U) return -1; if (util_rotr32(0x00000001U, 1) != 0x80000000U) return -1;
if (util_rotr32(0x80000000U, 1) != 0x40000000U) return -1; if (util_rotr32(0x80000000U, 1) != 0x40000000U) return -1;
if (util_rotr32(0x00000002U, 1) != 0x00000001U) return -1; if (util_rotr32(0x00000002U, 1) != 0x00000001U) return -1;
if (util_rotr32(0x12345678U, 4) != 0x81234567U) 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 */ /* rotate left 64-bit */
if (util_rotl64(1ULL, 1) != 2ULL) return -1; if (util_rotl64(1ULL, 1) != 2ULL) return -1;
if (util_rotl64(1ULL << 63, 1) != 1ULL) return -1; if (util_rotl64(1ULL << 63, 1) != 1ULL) return -1;
if (util_rotl64(0x123456789ABCDEF0ULL, 8) != 0x3456789ABCDEF012ULL) return -1; if (util_rotl64(0x123456789ABCDEF0ULL, 8) != 0x3456789ABCDEF012ULL) return -1;
if (util_rotl64(0x123456789ABCDEF0ULL, 0) != 0x123456789ABCDEF0ULL) return -1; if (util_rotl64(0x123456789ABCDEF0ULL, 0) != 0x123456789ABCDEF0ULL) return -1;
if (util_rotl64(0x123456789ABCDEF0ULL, 64) != 0x123456789ABCDEF0ULL) return -1;
/* rotate right 64-bit */ /* rotate right 64-bit */
if (util_rotr64(1ULL, 1) != (1ULL << 63)) return -1; if (util_rotr64(1ULL, 1) != (1ULL << 63)) return -1;
if (util_rotr64(2ULL, 1) != 1ULL) return -1; if (util_rotr64(2ULL, 1) != 1ULL) return -1;
if (util_rotr64(0x123456789ABCDEF0ULL, 8) != 0xF0123456789ABCDEULL) 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 */ /* util_mum tests */
uint64_t a, b; uint64_t a, b;

1
configure.analyzer Executable file
View file

@ -0,0 +1 @@
./configure CC=/usr/libexec/ccc-analyzer

View file

@ -1592,8 +1592,8 @@ void os_abort(void)
unsigned i; unsigned i;
#endif #endif
const char* platform = ""; const char* platform;
const char* compiler = ""; const char* compiler;
#ifdef _linux #ifdef _linux
platform = ", linux"; platform = ", linux";
@ -1601,12 +1601,16 @@ void os_abort(void)
platform = ", macOS"; platform = ", macOS";
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
platform = ", FreeBSD"; platform = ", FreeBSD";
#else
platform = "";
#endif #endif
#if defined(__clang__) #if defined(__clang__)
compiler = ", clang " __clang_version__; compiler = ", clang " __clang_version__;
#elif defined(__GNUC__) #elif defined(__GNUC__)
compiler = ", gcc " __VERSION__; compiler = ", gcc " __VERSION__;
#else
compiler = "";
#endif #endif
os_syslog(OS_LVL_CRITICAL, "Stacktrace of " PACKAGE " v" VERSION os_syslog(OS_LVL_CRITICAL, "Stacktrace of " PACKAGE " v" VERSION