summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParthiban Nallathambi <[email protected]>2026-11-06 15:13:43 +0530
committerRbb666 <[email protected]>2026-11-23 09:51:23 +0800
commit89fd2c8ee5822ba9272b525b59d1729804160234 (patch)
treea61b2054403ac9920a482f9f9f36d04a0cab9da0
parent6fdfe70062ec394e5dd7099c51cbcff127cacab1 (diff)
[utest][klibc] Keep TC_rt_memmove_too_long inside its buffers
The test copied 11 bytes from a 6-byte source into a 10-byte buffer. It corrupted the stack at -O2 on RH850. Copy 11 bytes between 11-byte buffers. Also check the bytes past the NUL, so a copy that stops early fails. Signed-off-by: Parthiban Nallathambi <[email protected]>
-rw-r--r--src/klibc/utest/TC_rt_memmove.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/klibc/utest/TC_rt_memmove.c b/src/klibc/utest/TC_rt_memmove.c
index 2486664f29..f07ff6b846 100644
--- a/src/klibc/utest/TC_rt_memmove.c
+++ b/src/klibc/utest/TC_rt_memmove.c
@@ -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>
@@ -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 */