]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Fix compiler warning with empty message assertion
authorTobias Brunner <tobias@strongswan.org>
Mon, 15 Jul 2024 14:55:29 +0000 (16:55 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 15 Jul 2024 14:55:29 +0000 (16:55 +0200)
The empty array of rules for `assert_message_empty()` and the resulting
size 0 triggers warnings like these:

  allocation of insufficient size '0' for type 'listener_message_rule_t' with size '12'

Using calloc() with `nmemb` set to 0 triggers the same warning.

src/libcharon/tests/utils/exchange_test_asserts.h

index a58832d7333c883d4e6bf07e427dd7508130bf38..e4ce81040379124c25f6d5a55b7272b4acc9e64d 100644 (file)
@@ -357,7 +357,7 @@ bool exchange_test_asserts_message(listener_t *this, ike_sa_t *ike_sa,
                .line = __LINE__, \
                .incoming = streq(dir, "IN") ? TRUE : FALSE, \
                .count = c, \
-               .rules = malloc(sizeof(_rules)), \
+               .rules = sizeof(_rules) ? malloc(sizeof(_rules)) : NULL, \
                .num_rules = countof(_rules), \
        ); \
        memcpy(_listener->rules, _rules, sizeof(_rules)); \