From: Yu Watanabe Date: Mon, 19 Dec 2022 12:07:39 +0000 (+0900) Subject: macro: check existence of cleanup function before call it X-Git-Tag: v253-rc1~227 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9c29d87beebf3a4d60639977494add18c45acba6;p=thirdparty%2Fsystemd.git macro: check existence of cleanup function before call it The free function specified in the macro may be provided by a dynamically loaded library. Replaces #25781. --- diff --git a/src/basic/macro.h b/src/basic/macro.h index 3d1b1751231..a00d60824dd 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -64,10 +64,14 @@ _Pragma("GCC diagnostic push") #endif -#define DISABLE_WARNING_TYPE_LIMITS \ +#define DISABLE_WARNING_TYPE_LIMITS \ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wtype-limits\"") +#define DISABLE_WARNING_ADDRESS \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Waddress\"") + #define REENABLE_WARNING \ _Pragma("GCC diagnostic pop") @@ -318,10 +322,14 @@ static inline int __coverity_check_and_return__(int condition) { *p = func(*p); \ } -/* When func() doesn't return the appropriate type, set variable to empty afterwards */ +/* When func() doesn't return the appropriate type, set variable to empty afterwards. + * The func() may be provided by a dynamically loaded shared library, hence add an assertion. */ #define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(type, func, empty) \ static inline void func##p(type *p) { \ if (*p != (empty)) { \ + DISABLE_WARNING_ADDRESS; \ + assert(func); \ + REENABLE_WARNING; \ func(*p); \ *p = (empty); \ } \