From e811994babf84e29e56ebf97265f5fefdf18050f Mon Sep 17 00:00:00 2001 From: Felix Conway Date: Wed, 11 Jun 2025 16:03:27 +0100 Subject: [PATCH 1/2] Add __attribute__ ((nonstring)) to remove unterminated-string-initialization warning Signed-off-by: Felix Conway --- tests/src/psa_exercise_key.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/psa_exercise_key.c b/tests/src/psa_exercise_key.c index 01fc143e7..b7b507465 100644 --- a/tests/src/psa_exercise_key.c +++ b/tests/src/psa_exercise_key.c @@ -184,7 +184,8 @@ static int exercise_cipher_key(mbedtls_svc_key_id_t key, psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_type_t key_type; const unsigned char plaintext[16] = "Hello, world..."; - unsigned char ciphertext[32] = "(wabblewebblewibblewobblewubble)"; + /* We need to tell the compiler that we meant to leave out the null character. */ + unsigned char ciphertext[32] __attribute__ ((nonstring)) = "(wabblewebblewibblewobblewubble)"; size_t ciphertext_length = sizeof(ciphertext); unsigned char decrypted[sizeof(ciphertext)]; size_t part_length; From 37d32e6b464f06f52ab4ef2497bb2e9e66a7fc26 Mon Sep 17 00:00:00 2001 From: Felix Conway Date: Thu, 12 Jun 2025 10:55:20 +0100 Subject: [PATCH 2/2] Replace __attribute__((nonstring)) with macro MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING This macro applies __attribute__((nonstring)) when the compiler supports it Signed-off-by: Felix Conway --- tests/src/psa_exercise_key.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/psa_exercise_key.c b/tests/src/psa_exercise_key.c index b7b507465..1b30c44c5 100644 --- a/tests/src/psa_exercise_key.c +++ b/tests/src/psa_exercise_key.c @@ -185,7 +185,8 @@ static int exercise_cipher_key(mbedtls_svc_key_id_t key, psa_key_type_t key_type; const unsigned char plaintext[16] = "Hello, world..."; /* We need to tell the compiler that we meant to leave out the null character. */ - unsigned char ciphertext[32] __attribute__ ((nonstring)) = "(wabblewebblewibblewobblewubble)"; + unsigned char ciphertext[32] MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING = + "(wabblewebblewibblewobblewubble)"; size_t ciphertext_length = sizeof(ciphertext); unsigned char decrypted[sizeof(ciphertext)]; size_t part_length;