Skip to content
Open
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
13 changes: 8 additions & 5 deletions src/klibc/utest/TC_rt_memmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2024-12-25 Meco Man first version
* 2026-11-06 Parthiban keep TC_rt_memmove_too_long inside its buffers
*/

#include <rtthread.h>
Expand Down Expand Up @@ -69,14 +70,16 @@ static void TC_rt_memmove_null_dest(void)
rt_memmove(RT_NULL, src, 0); /* Should not crash and do nothing */
}

/* Move more than source size */
/* Move more than the string length */
static void TC_rt_memmove_too_long(void)
{
char src[] = "Short";
char dest[10] = { 0 };
rt_memmove(dest, src, sizeof(src) + 5); /* Should only copy up to src length */
char src[11] = { 'S', 'h', 'o', 'r', 't', '\0', 'X', 'Y', 'Z', 'W', 'V' };
char dest[11];

rt_memset(dest, 0xAA, sizeof(dest));
rt_memmove(dest, src, sizeof(src)); /* all 11 bytes, also past the NUL */
uassert_str_equal(dest, "Short");
uassert_int_equal(dest[5], 0); /* Ensure no buffer overflow */
uassert_buf_equal(dest, src, sizeof(src));
}

/* Move empty string */
Expand Down
Loading