From e7a7013910067fcf7a32a036991a67b66c2dbe6a Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 20 Feb 2024 11:49:54 +0100 Subject: [PATCH] Remove initialization function for variable-length struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assigning the return value of a function that returns a struct with a flexible array member does not fill the flexible array member, which leaves a gap in the initialization that could be surprising to programmers. Also, this is a borderline case in ABI design which could cause interoperability problems. So remove this function. This gets rid of an annoying note from GCC about ABI compatibility on (at least) x86_64. ``` In file included from include/psa/crypto.h:4820, from :1: include/psa/crypto_struct.h: In function ‘psa_key_generation_method_init’: include/psa/crypto_struct.h:244:1: note: the ABI of passing struct with a flexible array member has changed in GCC 4.4 244 | { | ^ ``` Signed-off-by: Gilles Peskine --- include/psa/crypto_struct.h | 7 ------- tests/suites/test_suite_psa_crypto.function | 2 -- 2 files changed, 9 deletions(-) diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h index 248caa2be..f41bc8305 100644 --- a/include/psa/crypto_struct.h +++ b/include/psa/crypto_struct.h @@ -239,13 +239,6 @@ struct psa_key_generation_method_s { */ #define PSA_KEY_GENERATION_METHOD_INIT { 0 } -static inline struct psa_key_generation_method_s psa_key_generation_method_init( - void) -{ - const struct psa_key_generation_method_s v = PSA_KEY_GENERATION_METHOD_INIT; - return v; -} - struct psa_key_policy_s { psa_key_usage_t MBEDTLS_PRIVATE(usage); psa_algorithm_t MBEDTLS_PRIVATE(alg); diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index e946f4e60..6cd1e93a2 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -9996,12 +9996,10 @@ exit: /* BEGIN_CASE */ void key_generation_method_init() { - psa_key_generation_method_t func = psa_key_generation_method_init(); psa_key_generation_method_t init = PSA_KEY_GENERATION_METHOD_INIT; psa_key_generation_method_t zero; memset(&zero, 0, sizeof(zero)); - TEST_EQUAL(func.flags, 0); TEST_EQUAL(init.flags, 0); TEST_EQUAL(zero.flags, 0); }