From 0dcdc0347c8d0405c1c6b444d23483dd9bf31d34 Mon Sep 17 00:00:00 2001 From: Yu-Ping Wu Date: Thu, 8 Aug 2024 17:20:05 +0800 Subject: commonlib/bsd: Add strlen() and strnlen() functions Add strlen() and strnlen() to commonlib/bsd by rewriting them from scratch, and remove the same functions from coreboot and libpayload. Note that in the existing libpayload implementation, these functions return 0 for NULL strings. Given that POSIX doesn't require the NULL check and that other major libc implementations (e.g. glibc [1]) don't seem to do that, the new functions also don't perform the NULL check. [1] https://github.com/bminor/glibc/blob/master/sysdeps/i386/strlen.c Change-Id: I1203ec9affabe493bd14b46662d212b08240cced Signed-off-by: Yu-Ping Wu Reviewed-on: https://review.coreboot.org/c/coreboot/+/83830 Reviewed-by: Maximilian Brune Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- tests/lib/string-test.c | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'tests/lib/string-test.c') diff --git a/tests/lib/string-test.c b/tests/lib/string-test.c index 17bb69ab56..527135353d 100644 --- a/tests/lib/string-test.c +++ b/tests/lib/string-test.c @@ -23,12 +23,6 @@ struct string_pairs_t { {"", ""}, }; -const char *strings[] = { - "coreboot", - "is\0very", - "nice\n" -}; - /* Used to test atol */ struct str_with_l_val_t { char *str; @@ -76,26 +70,6 @@ static void test_strconcat(void **state) } } -static void test_strnlen(void **state) -{ - int i, n = 5; - size_t str_len, limited_len; - - for (i = 0; i < ARRAY_SIZE(strings); i++) { - str_len = __builtin_strlen(strings[i]); - limited_len = MIN(n, str_len); - assert_int_equal(limited_len, strnlen(strings[i], n)); - } -} - -static void test_strlen(void **state) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(strings); i++) - assert_int_equal(__builtin_strlen(strings[i]), strlen(strings[i])); -} - static void test_strchr(void **state) { char str[] = "Abracadabra!\n"; @@ -227,8 +201,6 @@ int main(void) const struct CMUnitTest tests[] = { cmocka_unit_test(test_strdup), cmocka_unit_test(test_strconcat), - cmocka_unit_test(test_strnlen), - cmocka_unit_test(test_strlen), cmocka_unit_test(test_strchr), cmocka_unit_test(test_strrchr), cmocka_unit_test(test_strncpy), -- cgit v1.2.3