From: Tobias Brunner Date: Thu, 19 May 2022 09:10:07 +0000 (+0200) Subject: object: Fix CALLBACK macros with GCC 12 X-Git-Tag: 5.9.7dr2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=993ea3282571b993ec2c631def5b6f3303b6d2f5;p=thirdparty%2Fstrongswan.git object: Fix CALLBACK macros with GCC 12 GCC 12 produces weird code when a callback is called directly (e.g. parse_bool() via parse_option() in vici_config.c). Instead of the actual pointer, it explicitly passes 0 as first argument, which likely causes a segmentation fault. It doesn't happen when called indirectly via function pointer that has void* as first argument, which this patch kinda replicates for direct calls to avoid the issue. Closes strongswan/strongswan#1053 --- diff --git a/src/libstrongswan/utils/utils/object.h b/src/libstrongswan/utils/utils/object.h index 174ea812a1..da580c01af 100644 --- a/src/libstrongswan/utils/utils/object.h +++ b/src/libstrongswan/utils/utils/object.h @@ -120,7 +120,7 @@ #define CALLBACK(name, ret, param1, ...) \ static ret _cb_##name(union {void *_generic; param1;} \ __attribute__((transparent_union)), ##__VA_ARGS__); \ - static typeof(_cb_##name) *name = (typeof(_cb_##name)*)_cb_##name; \ + static ret (*name)(void*, ##__VA_ARGS__) = _cb_##name; \ static ret _cb_##name(param1, ##__VA_ARGS__) /** @@ -131,7 +131,7 @@ __attribute__((transparent_union)), \ union {void *_generic; param2;} \ __attribute__((transparent_union)), ##__VA_ARGS__); \ - static typeof(_cb_##name) *name = (typeof(_cb_##name)*)_cb_##name; \ + static ret (*name)(void*, void*, ##__VA_ARGS__) = _cb_##name; \ static ret _cb_##name(param1, param2, ##__VA_ARGS__) #endif /** OBJECT_H_ @} */