]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bitfield: check if specified index is non-negative
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Mar 2025 00:38:36 +0000 (09:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Mar 2025 00:56:04 +0000 (09:56 +0900)
Hopefully silences false-positive warnings by Coverity e.g. CID#1590746.

src/basic/bitfield.h

index 048e08d753487ed1f8c7b7875618fd4ae43ff030..c6eaaa484fea3418f9a32136a2fe0dc95da8de08 100644 (file)
@@ -7,6 +7,7 @@
 #define _INDEX_TO_MASK(type, i, uniq)                                   \
         ({                                                              \
                 int UNIQ_T(_i, uniq) = (i);                             \
+                assert(UNIQ_T(_i, uniq) >= 0);                          \
                 assert(UNIQ_T(_i, uniq) < (int)sizeof(type) * 8);       \
                 ((type)1) << UNIQ_T(_i, uniq);                          \
         })