From 1b70a59ded904dafb61b9b3d88381c3085469d64 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sat, 26 Apr 2025 20:32:23 +0200 Subject: [PATCH] tree-wide: add the NONSTRING attribute where needed This declares all char arrays that intentionally are lacking the terminated zero byte as `NONSTRING`. --- sys/fmt/fmt.c | 2 ++ sys/fmt/table.c | 2 ++ tests/bench/sys_base64/main.c | 5 +++++ tests/sys/psa_crypto/main.c | 3 +++ tests/sys/psa_crypto_ecdsa/test_ecdsa_p256_vectors.c | 2 ++ tests/sys/struct_tm_utility/main.c | 4 ++++ tests/unittests/tests-fmt/tests-fmt.c | 9 +++++++++ 7 files changed, 27 insertions(+) diff --git a/sys/fmt/fmt.c b/sys/fmt/fmt.c index b961b4511e..199cd9c0f8 100644 --- a/sys/fmt/fmt.c +++ b/sys/fmt/fmt.c @@ -27,12 +27,14 @@ #include #include +#include "compiler_hints.h" #include "container.h" #include "fmt.h" #include "modules.h" extern ssize_t stdio_write(const void* buffer, size_t len); +NONSTRING static const char _hex_chars[16] = "0123456789ABCDEF"; static const uint32_t _tenmap[] = { diff --git a/sys/fmt/table.c b/sys/fmt/table.c index c0c0308c57..8689f88307 100644 --- a/sys/fmt/table.c +++ b/sys/fmt/table.c @@ -24,9 +24,11 @@ #include #include +#include "compiler_hints.h" #include "fmt.h" #include "fmt_table.h" +NONSTRING static const char fmt_table_spaces[16] = " "; /** diff --git a/tests/bench/sys_base64/main.c b/tests/bench/sys_base64/main.c index cea7e19fb7..c4165030f9 100644 --- a/tests/bench/sys_base64/main.c +++ b/tests/bench/sys_base64/main.c @@ -22,15 +22,20 @@ #include #include "base64.h" +#include "compiler_hints.h" #include "fmt.h" #include "macros/utils.h" #include "xtimer.h" static char buf[128]; +/* no need for the zero-termination here, base64_encode() gets the size of the + * string as explicit argument */ +NONSTRING static const char input[96] = "This is an extremely, enormously, greatly, " "immensely, tremendously, remarkably lengthy " "sentence!"; +NONSTRING static const char base64[128] = "VGhpcyBpcyBhbiBleHRyZW1lbHksIGVub3Jtb3VzbHksIGdyZWF0bHksIGltbWVuc2VseSwgdHJl" "bWVuZG91c2x5LCByZW1hcmthYmx5IGxlbmd0aHkgc2VudGVuY2Uh"; diff --git a/tests/sys/psa_crypto/main.c b/tests/sys/psa_crypto/main.c index 0feffca843..4912a49963 100644 --- a/tests/sys/psa_crypto/main.c +++ b/tests/sys/psa_crypto/main.c @@ -20,6 +20,7 @@ #include #include "embUnit.h" +#include "compiler_hints.h" #include "psa/crypto.h" void addFailurePSA(const char *func, psa_status_t errcode, long line, const char *file) @@ -73,7 +74,9 @@ static void test_hash_interleaved(void) { const psa_algorithm_t alg = PSA_ALG_SHA_256; + NONSTRING const uint8_t in1[1] = "a"; + NONSTRING const uint8_t in2[1] = "b"; const uint8_t exp1[] = { diff --git a/tests/sys/psa_crypto_ecdsa/test_ecdsa_p256_vectors.c b/tests/sys/psa_crypto_ecdsa/test_ecdsa_p256_vectors.c index c3697221d3..572a2c515f 100644 --- a/tests/sys/psa_crypto_ecdsa/test_ecdsa_p256_vectors.c +++ b/tests/sys/psa_crypto_ecdsa/test_ecdsa_p256_vectors.c @@ -20,6 +20,7 @@ #include #include +#include "compiler_hints.h" #include "psa/crypto.h" /* @@ -42,6 +43,7 @@ static const uint8_t public_key[] = {0x04, 0x60, 0xFE, 0xD4, 0xBA, 0x25, 0x5A, 0 /* certain PSA backends require the data to be in RAM rather than ROM * so these values cannot be `const` */ +NONSTRING static uint8_t message[6] = "sample"; static uint8_t signature[] = {0xEF, 0xD4, 0x8B, 0x2A, 0xAC, 0xB6, 0xA8, 0xFD, 0x11, 0x40, 0xDD, 0x9C, 0xD4, 0x5E, 0x81, 0xD6, 0x9D, 0x2C, 0x87, 0x7B, 0x56, 0xAA, 0xF9, 0x91, 0xC3, 0x4D, diff --git a/tests/sys/struct_tm_utility/main.c b/tests/sys/struct_tm_utility/main.c index 804ea50423..c21ece1735 100644 --- a/tests/sys/struct_tm_utility/main.c +++ b/tests/sys/struct_tm_utility/main.c @@ -29,17 +29,21 @@ #include #include +#include "compiler_hints.h" #include "shell.h" #include "tm.h" +NONSTRING static const char MON_NAMES[12][3] = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC", }; +NONSTRING static const char DAY_NAMES[7][3] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; +NONSTRING static const char BOOL_NAMES[2][3] = { "NO", "YES" }; bool proper_atoi(const char *a, int *i) diff --git a/tests/unittests/tests-fmt/tests-fmt.c b/tests/unittests/tests-fmt/tests-fmt.c index e707e8056f..dec1186bed 100644 --- a/tests/unittests/tests-fmt/tests-fmt.c +++ b/tests/unittests/tests-fmt/tests-fmt.c @@ -17,6 +17,7 @@ #include "embUnit/embUnit.h" +#include "compiler_hints.h" #include "fmt.h" #include "tests-fmt.h" @@ -244,6 +245,7 @@ static void test_fmt_hex_bytes(void) static void test_fmt_u16_hex(void) { + NONSTRING char out[8] = "zzzzzzzz"; /* Check return count with null buffer input */ @@ -260,6 +262,7 @@ static void test_fmt_u16_hex(void) static void test_fmt_u32_hex(void) { + NONSTRING char out[12] = "zzzzzzzzzzzz"; /* Check return count with null buffer input */ @@ -276,6 +279,7 @@ static void test_fmt_u32_hex(void) static void test_fmt_u64_hex(void) { + NONSTRING char out[20] = "zzzzzzzzzzzzzzzzzzzz"; /* Check return count with null buffer input */ @@ -292,6 +296,7 @@ static void test_fmt_u64_hex(void) static void test_fmt_u16_dec(void) { + NONSTRING char out[8] = "zzzzzzzz"; uint8_t chars = 0; @@ -310,6 +315,7 @@ static void test_fmt_u16_dec(void) static void test_fmt_u32_dec(void) { + NONSTRING char out[16] = "zzzzzzzzzzzzzzzz"; uint8_t chars = 0; @@ -329,6 +335,7 @@ static void test_fmt_u32_dec(void) static void test_fmt_u64_dec(void) { + NONSTRING char out[24] = "zzzzzzzzzzzzzzzzzzzzzzzz"; uint8_t chars = 0; @@ -345,6 +352,7 @@ static void test_fmt_u64_dec(void) static void test_fmt_u64_dec_zero(void) { + NONSTRING char out[24] = "zzzzzzzzzzzzzzzzzzzzzzzz"; uint8_t chars = 0; @@ -355,6 +363,7 @@ static void test_fmt_u64_dec_zero(void) static void test_fmt_u64_dec_u64max(void) { + NONSTRING char out[24] = "zzzzzzzzzzzzzzzzzzzzzzzz"; uint8_t chars = 0;