diff --git a/tests/unit/test_memory.c b/tests/unit/test_memory.c index 80481f44..83ca75a0 100644 --- a/tests/unit/test_memory.c +++ b/tests/unit/test_memory.c @@ -99,6 +99,7 @@ void test_safe_strcpy_success(void) { void test_safe_strcpy_truncation_returns_error(void) { char buf[4]; + memset(buf, 0, sizeof(buf)); int rc = safe_strcpy(buf, "hello_world", sizeof(buf)); TEST_ASSERT_NOT_EQUAL(0, rc); /* buf should still be null-terminated and contain truncated data */ @@ -121,6 +122,9 @@ void test_safe_strcat_overflow_returns_error(void) { char buf[8] = "hello"; int rc = safe_strcat(buf, "_overflow", sizeof(buf)); TEST_ASSERT_NOT_EQUAL(0, rc); + /* Buffer should remain a valid, null-terminated string and keep its safe content */ + TEST_ASSERT_EQUAL_INT('\0', buf[sizeof(buf) - 1] == '\0' ? '\0' : buf[sizeof(buf) - 1]); + TEST_ASSERT_EQUAL_STRING_LEN("hello", buf, 5); } /* ================================================================