diff mbox series

[v2,2/2] unit: Add l_safe_memcpy test

Message ID 20241031161928.1514776-2-denkenz@gmail.com (mailing list archive)
State New
Headers show
Series [v2,1/2] util: Add l_safe_memcpy | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

Denis Kenzior Oct. 31, 2024, 4:19 p.m. UTC
---
 unit/test-util.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/unit/test-util.c b/unit/test-util.c
index 341c790c3731..4d4e2e91a47c 100644
--- a/unit/test-util.c
+++ b/unit/test-util.c
@@ -288,6 +288,16 @@  static void test_roundup_pow_of_two(const void *test_data)
 	}
 }
 
+static void test_safe_memcpy(const void *test_data)
+{
+	static const uint8_t src[] = { 0x00, 0xff, 0xff, 0xff };
+	uint8_t dst[10];
+
+	assert(l_safe_memcpy(dst, src, sizeof(src)) == dst);
+	assert(l_safe_memcpy(dst, src, 0) == dst);
+	assert(l_safe_memcpy(dst, NULL, 0) == dst);
+}
+
 int main(int argc, char *argv[])
 {
 	l_test_init(&argc, &argv);
@@ -313,5 +323,7 @@  int main(int argc, char *argv[])
 
 	l_test_add("roundup_pow_of_two", test_roundup_pow_of_two, NULL);
 
+	l_test_add("l_safememcpy", test_safe_memcpy, NULL);
+
 	return l_test_run();
 }