]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
object: Make INIT() a compound statement
authorTobias Brunner <tobias@strongswan.org>
Thu, 29 Sep 2022 09:36:00 +0000 (11:36 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 29 Sep 2022 09:36:00 +0000 (11:36 +0200)
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
src/libstrongswan/utils/utils/object.h
src/sw-collector/sw_collector_history.c

index a61e08c980fa51cd3c9c229f0d9469fe0efa3da4..1f87189623797f45fd557ccbbdf0a40866b89760 100644 (file)
@@ -266,7 +266,7 @@ static array_t *select_signature_schemes(keymat_v2_t *keymat,
                                {
                                        INIT(config,
                                                .scheme = scheme,
-                                       )
+                                       );
                                        array_insert(selected, ARRAY_TAIL, config);
                                }
                        }
index fc591680447e7742d029b1d0a33b887d87015780..6ace60041df986a1360b2a79f7d94a942228e92f 100644 (file)
@@ -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().
index 2cecb2c1326537e2f9fceff1ae1519199fac6be0..5a26ff12b4961125e75249a740f80d9e51be4e6d 100644 (file)
@@ -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)