--- a/tests/test_string.c Wed Dec 31 12:24:39 2025 +0100 +++ b/tests/test_string.c Wed Dec 31 12:33:16 2025 +0100 @@ -595,6 +595,36 @@ cx_testing_allocator_destroy(&talloc); } +CX_TEST(test_strcat_zero) { + CxTestingAllocator talloc; + cx_testing_allocator_init(&talloc); + CxAllocator *alloc = &talloc.base; + + CX_TEST_DO { + cxmutstr t1 = cx_strcat_a(alloc, CX_NULLSTR, 0); + CX_TEST_ASSERT(0 == cx_strcmp(t1, "")); + ASSERT_ZERO_TERMINATED(t1); + cx_strfree_a(alloc, &t1); + + cxmutstr s2 = cx_strdup_a(alloc, "testing"); + s2.length = 4; + cxmutstr t2 = cx_strcat_a(alloc, s2, 0); + CX_TEST_ASSERT(0 == cx_strcmp(t2, "test")); + ASSERT_ZERO_TERMINATED(t2); + cx_strfree_a(alloc, &t2); + + cxmutstr s3 = cx_strdup_a(alloc, "fake"); + s3.length = 0; + cxmutstr t3 = cx_strcat_a(alloc, s3, 0); + CX_TEST_ASSERT(0 == cx_strcmp(t3, "")); + ASSERT_ZERO_TERMINATED(t3); + cx_strfree_a(alloc, &t3); + + CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); + } + cx_testing_allocator_destroy(&talloc); +} + CX_TEST(test_strcat_more_than_eight) { cxstring s1 = cx_str("12"); cxstring s2 = cx_str("34"); @@ -1684,6 +1714,7 @@ cx_test_register(suite, test_strcmp); cx_test_register(suite, test_strcasecmp); cx_test_register(suite, test_strcat); + cx_test_register(suite, test_strcat_zero); cx_test_register(suite, test_strcat_more_than_eight); cx_test_register(suite, test_strsplit); cx_test_register(suite, test_strsplit_a);