From e0fd191f314f1b3e2ec4ebe18de99df338d2e8d0 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 29 Sep 2022 11:36:00 +0200 Subject: [PATCH] object: Make INIT() a compound statement This forces the use of a semicolon after INIT() and makes existing ones, which was the case for basically all instances, necessary so e.g. sonarcloud won't complain about an empty statement after every one of them. By evaluating to the allocated object, it would theoretically also allow constructs like this: struct_t *this; return INIT(this, .a = x, .b = y, ); or this: array_insert(a, ARRAY_TAIL, INIT(this, .a = x, .b = y, )); --- src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c | 2 +- src/libstrongswan/utils/utils/object.h | 4 ++-- src/sw-collector/sw_collector_history.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c b/src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c index a61e08c980..1f87189623 100644 --- a/src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c +++ b/src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c @@ -266,7 +266,7 @@ static array_t *select_signature_schemes(keymat_v2_t *keymat, { INIT(config, .scheme = scheme, - ) + ); array_insert(selected, ARRAY_TAIL, config); } } diff --git a/src/libstrongswan/utils/utils/object.h b/src/libstrongswan/utils/utils/object.h index fc59168044..6ace60041d 100644 --- a/src/libstrongswan/utils/utils/object.h +++ b/src/libstrongswan/utils/utils/object.h @@ -41,8 +41,8 @@ /** * Object allocation/initialization macro, using designated initializer. */ -#define INIT(this, ...) { (this) = malloc(sizeof(*(this))); \ - *(this) = (typeof(*(this))){ __VA_ARGS__ }; } +#define INIT(this, ...) ({ (this) = malloc(sizeof(*(this))); \ + *(this) = (typeof(*(this))){ __VA_ARGS__ }; (this); }) /** * Aligning version of INIT(). diff --git a/src/sw-collector/sw_collector_history.c b/src/sw-collector/sw_collector_history.c index 2cecb2c132..5a26ff12b4 100644 --- a/src/sw-collector/sw_collector_history.c +++ b/src/sw-collector/sw_collector_history.c @@ -78,7 +78,7 @@ static package_t* create_package(swid_gen_info_t *info, chunk_t package, .package = strndup(package.ptr, package.len), .version = strndup(version.ptr, version.len), .old_version = strndup(old_version.ptr, old_version.len), - ) + ); this->sw_id = info->create_sw_id(info, this->package, this->version); if (old_version.len) -- 2.47.2