Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/unit/test_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
}

/* ================================================================
Expand Down
Loading