From: Emil Velikov Date: Mon, 30 Sep 2024 19:52:18 +0000 (+0100) Subject: shared: tweak addu64_overflow() #if/else chain X-Git-Tag: v34~250 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8fa87bf4aa4e0f38426fb233e3dc5b22f8b3bb1d;p=thirdparty%2Fkmod.git shared: tweak addu64_overflow() #if/else chain 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 Link: https://github.com/kmod-project/kmod/pull/169 Signed-off-by: Lucas De Marchi --- diff --git a/shared/util.h b/shared/util.h index bcd834e5..9bea2733 100644 --- a/shared/util.h +++ b/shared/util.h @@ -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 }