From 1d14555d3a4501adae909884bcb8f8a0b142c89c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 9 Jan 2023 12:43:22 +1030 Subject: [PATCH] antithread, htable, ilog: more misc sanitizer complaints. Signed-off-by: Rusty Russell --- ccan/antithread/alloc/tiny.c | 3 ++- ccan/htable/htable_type.h | 3 +-- ccan/ilog/ilog.h | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ccan/antithread/alloc/tiny.c b/ccan/antithread/alloc/tiny.c index ffd17c65..d84974ee 100644 --- a/ccan/antithread/alloc/tiny.c +++ b/ccan/antithread/alloc/tiny.c @@ -353,7 +353,8 @@ bool tiny_alloc_check(void *pool, unsigned long poolsize) unsigned long arrsize = free_array_size(poolsize); unsigned char *arr = pool; unsigned long len, off, hdrlen; - unsigned long i, freearr[arrsize], num_freearr = 0; + /* Don't have sanitizer complain here if arrsize is 0! */ + unsigned long i, freearr[arrsize ? arrsize : 1], num_freearr = 0; bool free; if (poolsize < MIN_BLOCK_SIZE) diff --git a/ccan/htable/htable_type.h b/ccan/htable/htable_type.h index bb5ea086..0aacb7f3 100644 --- a/ccan/htable/htable_type.h +++ b/ccan/htable/htable_type.h @@ -159,8 +159,7 @@ size_t seed, \ struct name##_iter *iter) \ { \ - /* Note &iter->i == NULL iff iter is NULL */ \ - return htable_pick(&ht->raw, seed, &iter->i); \ + return htable_pick(&ht->raw, seed, iter ? &iter->i : NULL); \ } \ static inline UNNEEDED type *name##_first(const struct name *ht, \ struct name##_iter *iter) \ diff --git a/ccan/ilog/ilog.h b/ccan/ilog/ilog.h index 9adbb824..32702b17 100644 --- a/ccan/ilog/ilog.h +++ b/ccan/ilog/ilog.h @@ -120,7 +120,10 @@ int ilog64_nz(uint64_t _v) CONST_FUNCTION; #endif #ifdef builtin_ilog32_nz -#define ilog32(_v) (builtin_ilog32_nz(_v)&-!!(_v)) +/* This used to be builtin_ilog32_nz(_v)&-!!(_v), which means it zeroes out + * the undefined builtin_ilog32_nz(0) return. But clang UndefinedBehaviorSantizer + * complains, so do the branch: */ +#define ilog32(_v) ((_v) ? builtin_ilog32_nz(_v) : 0) #define ilog32_nz(_v) builtin_ilog32_nz(_v) #else #define ilog32_nz(_v) ilog32(_v) @@ -128,7 +131,7 @@ int ilog64_nz(uint64_t _v) CONST_FUNCTION; #endif /* builtin_ilog32_nz */ #ifdef builtin_ilog64_nz -#define ilog64(_v) (builtin_ilog64_nz(_v)&-!!(_v)) +#define ilog32(_v) ((_v) ? builtin_ilog32_nz(_v) : 0) #define ilog64_nz(_v) builtin_ilog64_nz(_v) #else #define ilog64_nz(_v) ilog64(_v) -- 2.39.2