]> git.ozlabs.org Git - ccan/commitdiff
antithread, htable, ilog: more misc sanitizer complaints.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 9 Jan 2023 02:13:22 +0000 (12:43 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 16 Mar 2023 23:22:47 +0000 (09:52 +1030)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/antithread/alloc/tiny.c
ccan/htable/htable_type.h
ccan/ilog/ilog.h

index ffd17c65734f881f1ca355ed9e1a5b705dd3ff46..d84974ee02cd3ce0f4c967c239e30e6b466f3241 100644 (file)
@@ -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)
index bb5ea086b7319fd3cd1c19b0dceece1974cfe8d4..0aacb7f334925ffe58d2c8cb489a9ae0efe36b66 100644 (file)
                                                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)      \
index 9adbb8243f6c4f67da7ccefbc8fc7735f63cda7e..32702b178567e503c11d606d655738fe9dbfc3aa 100644 (file)
@@ -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)