1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

Add __attribute__ ((nonstring)) to remove unterminated-string-initialization warning

Signed-off-by: Felix Conway <felix.conway@arm.com>
This commit is contained in:
Felix Conway
2025-06-11 16:04:30 +01:00
parent 4c26d7d54c
commit 2e1399f1e1
5 changed files with 14 additions and 8 deletions

View File

@ -82,7 +82,8 @@ struct mbedtls_ssl_tls13_labels_struct const mbedtls_ssl_tls13_labels =
* the HkdfLabel structure on success. * the HkdfLabel structure on success.
*/ */
static const char tls13_label_prefix[6] = "tls13 "; /* We need to tell the compiler that we meant to leave out the null character. */
static const char tls13_label_prefix[6] __attribute__ ((nonstring)) = "tls13 ";
#define SSL_TLS1_3_KEY_SCHEDULE_HKDF_LABEL_LEN(label_len, context_len) \ #define SSL_TLS1_3_KEY_SCHEDULE_HKDF_LABEL_LEN(label_len, context_len) \
(2 /* expansion length */ \ (2 /* expansion length */ \

View File

@ -40,8 +40,9 @@
#if defined(MBEDTLS_SSL_PROTO_TLS1_3) #if defined(MBEDTLS_SSL_PROTO_TLS1_3)
/* We need to tell the compiler that we meant to leave out the null character. */
#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \ #define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \
const unsigned char name [sizeof(string) - 1]; const unsigned char name [sizeof(string) - 1] __attribute__ ((nonstring));
union mbedtls_ssl_tls13_labels_union { union mbedtls_ssl_tls13_labels_union {
MBEDTLS_SSL_TLS1_3_LABEL_LIST MBEDTLS_SSL_TLS1_3_LABEL_LIST

View File

@ -3480,7 +3480,8 @@ void mac_setup(int key_type_arg,
psa_mac_operation_t operation = psa_mac_operation_init_short(); psa_mac_operation_t operation = psa_mac_operation_init_short();
psa_status_t status = PSA_ERROR_GENERIC_ERROR; psa_status_t status = PSA_ERROR_GENERIC_ERROR;
#if defined(KNOWN_SUPPORTED_MAC_ALG) #if defined(KNOWN_SUPPORTED_MAC_ALG)
const uint8_t smoke_test_key_data[16] = "kkkkkkkkkkkkkkkk"; /* We need to tell the compiler that we meant to leave out the null character. */
const uint8_t smoke_test_key_data[16] __attribute__ ((nonstring)) = "kkkkkkkkkkkkkkkk";
#endif #endif
PSA_ASSERT(psa_crypto_init()); PSA_ASSERT(psa_crypto_init());
@ -3917,7 +3918,8 @@ void cipher_setup(int key_type_arg,
psa_cipher_operation_t operation = psa_cipher_operation_init_short(); psa_cipher_operation_t operation = psa_cipher_operation_init_short();
psa_status_t status; psa_status_t status;
#if defined(KNOWN_SUPPORTED_CIPHER_ALG) #if defined(KNOWN_SUPPORTED_CIPHER_ALG)
const uint8_t smoke_test_key_data[16] = "kkkkkkkkkkkkkkkk"; /* We need to tell the compiler that we meant to leave out the null character. */
const uint8_t smoke_test_key_data[16] __attribute__ ((nonstring)) = "kkkkkkkkkkkkkkkk";
#endif #endif
PSA_ASSERT(psa_crypto_init()); PSA_ASSERT(psa_crypto_init());

View File

@ -377,8 +377,9 @@ void create_existent(int lifetime_arg, int owner_id_arg, int id_arg,
mbedtls_svc_key_id_t returned_id = MBEDTLS_SVC_KEY_ID_INIT; mbedtls_svc_key_id_t returned_id = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t type1 = PSA_KEY_TYPE_RAW_DATA; psa_key_type_t type1 = PSA_KEY_TYPE_RAW_DATA;
const uint8_t material1[5] = "a key"; /* We need to tell the compiler that we meant to leave out the null character. */
const uint8_t material2[5] = "b key"; const uint8_t material1[5] __attribute__ ((nonstring)) = "a key";
const uint8_t material2[5] __attribute__ ((nonstring)) = "b key";
size_t bits1 = PSA_BYTES_TO_BITS(sizeof(material1)); size_t bits1 = PSA_BYTES_TO_BITS(sizeof(material1));
uint8_t reexported[sizeof(material1)]; uint8_t reexported[sizeof(material1)];
size_t reexported_length; size_t reexported_length;
@ -747,7 +748,7 @@ void invalid_handle(int handle_construction,
psa_key_id_t key_id; psa_key_id_t key_id;
psa_status_t close_status = close_status_arg; psa_status_t close_status = close_status_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t material[1] = "a"; uint8_t material[1] = { 'a' };
PSA_ASSERT(psa_crypto_init()); PSA_ASSERT(psa_crypto_init());

View File

@ -37,7 +37,8 @@ void ssl_decrypt_null(int hash_id)
mbedtls_ssl_write_version(rec_good.ver, mbedtls_ssl_write_version(rec_good.ver,
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_TRANSPORT_STREAM,
version); version);
const char sample_plaintext[3] = "ABC"; /* We need to tell the compiler that we meant to leave out the null character. */
const char sample_plaintext[3] __attribute__ ((nonstring)) = "ABC";
mbedtls_ssl_context ssl; mbedtls_ssl_context ssl;
mbedtls_ssl_init(&ssl); mbedtls_ssl_init(&ssl);
uint8_t *buf = NULL; uint8_t *buf = NULL;