]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
shared: tweak addu64_overflow() #if/else chain
authorEmil Velikov <emil.l.velikov@gmail.com>
Mon, 30 Sep 2024 19:52:18 +0000 (20:52 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 15 Oct 2024 17:35:38 +0000 (12:35 -0500)
Group the checks as applicable - require the long variant when
sizeof(long) == 8, or the long long one as sizeof(long long) == 8.

Ultimately, fold fallback in the #else path, since it's dead code atm
and seemingly confuses tools such as Coverity.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/169
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared/util.h

index bcd834e5b371f98aa0ba1b188a3186375ac92171..9bea27335d8f53f328d3a0c00fe31dd270c4f817 100644 (file)
@@ -94,15 +94,12 @@ static inline void freep(void *p)
 
 static inline bool addu64_overflow(uint64_t a, uint64_t b, uint64_t *res)
 {
-#if (HAVE___BUILTIN_UADDL_OVERFLOW && HAVE___BUILTIN_UADDLL_OVERFLOW)
-#if __SIZEOF_LONG__ == 8
+#if (HAVE___BUILTIN_UADDL_OVERFLOW && __SIZEOF_LONG__ == 8)
        return __builtin_uaddl_overflow(a, b, res);
-#elif __SIZEOF_LONG_LONG__ == 8
+#elif (HAVE___BUILTIN_UADDLL_OVERFLOW && __SIZEOF_LONG_LONG__ == 8)
        return __builtin_uaddll_overflow(a, b, res);
 #else
-#error "sizeof(long long) != 8"
-#endif
-#endif
        *res = a + b;
        return UINT64_MAX - a < b;
+#endif
 }