]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: ENUM_NEGATE() - Disable runtime sizeof() check with STATIC_CHECKER
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 10 Sep 2021 16:00:09 +0000 (19:00 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 10 Sep 2021 16:18:03 +0000 (19:18 +0300)
This is to avoid "Dangerous variable-length array (VLA) declaration"
errors with clang 12 scan-build, which happen because scan-build keeps
thinking that the enums can become larger than 2147483647.

src/lib/macros.h

index c264ec6066b052e7bc44c87c5ae7a4b1b929aa3e..d41570a2827cb16cfc89392097c141ce3fc46c5c 100644 (file)
 #endif
 
 /* negate enumeration flags in a way that avoids implicit conversion */
-#define ENUM_NEGATE(x) \
+#ifndef STATIC_CHECKER
+#  define ENUM_NEGATE(x) \
        ((unsigned int)(~(x)) + COMPILE_ERROR_IF_TRUE(sizeof((x)) > sizeof(int) || (x) < 0 || (x) > INT_MAX))
+#else
+/* clang scan-build keeps complaining about x > 2147483647 case, so disable the
+   sizeof check. */
+#  define ENUM_NEGATE(x) ((unsigned int)(~(x)))
+#endif