From fdad37bc1854a973424459026cc32698ff5fe532 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 16 Apr 2026 12:54:34 -0400 Subject: Convert more strcpy to strn variant --- tests/test_str.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/test_str.c') diff --git a/tests/test_str.c b/tests/test_str.c index a98a34d..5679078 100644 --- a/tests/test_str.c +++ b/tests/test_str.c @@ -37,7 +37,7 @@ void test_tolower_s() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char input[100] = {0}; - strcpy(input, tc[i].data); + strncpy(input, tc[i].data, sizeof(input) - 1); tolower_s(input); STASIS_ASSERT(strcmp(input, tc[i].expected) == 0, "unexpected result"); } @@ -318,7 +318,7 @@ void test_lstrip() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *buf = calloc(255, sizeof(*buf)); char *result; - strcpy(buf, tc[i].data); + strncpy(buf, tc[i].data, sizeof(buf) - 1); result = lstrip(buf); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-left"); guard_free(buf); @@ -342,9 +342,8 @@ void test_strip() { STASIS_ASSERT(strip(NULL) == NULL, "incorrect return type"); for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *buf = calloc(255, sizeof(*buf)); - char *result; - strcpy(buf, tc[i].data); - result = strip(buf); + strncpy(buf, tc[i].data, sizeof(buf) - 1); + char *result = strip(buf); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-right"); guard_free(buf); } -- cgit From fa60a725478ca8ebade66a9031488501eb557820 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 16 Apr 2026 12:57:44 -0400 Subject: Remove sizeof call --- tests/test_str.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/test_str.c') diff --git a/tests/test_str.c b/tests/test_str.c index 5679078..85c8fb9 100644 --- a/tests/test_str.c +++ b/tests/test_str.c @@ -317,9 +317,8 @@ void test_lstrip() { STASIS_ASSERT(lstrip(NULL) == NULL, "incorrect return type"); for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *buf = calloc(255, sizeof(*buf)); - char *result; - strncpy(buf, tc[i].data, sizeof(buf) - 1); - result = lstrip(buf); + strncpy(buf, tc[i].data, 254); + char *result = lstrip(buf); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-left"); guard_free(buf); } -- cgit From f9bad6c9d5a5cbfb4dd9d45c55674a58c029c306 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 16 Apr 2026 12:57:47 -0400 Subject: Remove sizeof call --- tests/test_str.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_str.c') diff --git a/tests/test_str.c b/tests/test_str.c index 85c8fb9..aac5d71 100644 --- a/tests/test_str.c +++ b/tests/test_str.c @@ -341,7 +341,7 @@ void test_strip() { STASIS_ASSERT(strip(NULL) == NULL, "incorrect return type"); for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *buf = calloc(255, sizeof(*buf)); - strncpy(buf, tc[i].data, sizeof(buf) - 1); + strncpy(buf, tc[i].data, 254); char *result = strip(buf); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-right"); guard_free(buf); -- cgit