From 324f8d7a4139a30f98447247db869ece8c3fcd96 Mon Sep 17 00:00:00 2001 From: Inaky Perez-Gonzalez Date: Wed, 16 Nov 2016 16:33:35 -0800 Subject: [PATCH] tests/legacy/kernel/test_libs: use memcpy() vs strncpy() Coverity complained about the use of strncpy() to fill up a buffer of size N with a string of the same size didn't leave room for the final \0. This is a valid concern; however, the usage is valid too, as the writer intended to create a pattern that later can be tested--addind a \0 would break the pattern. So instead, use memcpy() for the same function. Change-Id: If52d02ce41731348f4a2d750c79f9e1c51f3afcf Coverity-ID: 151947 Signed-off-by: Inaky Perez-Gonzalez --- tests/legacy/kernel/test_libs/src/libraries.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/legacy/kernel/test_libs/src/libraries.c b/tests/legacy/kernel/test_libs/src/libraries.c index e2262a253ac..4bb9f1eb0f2 100644 --- a/tests/legacy/kernel/test_libs/src/libraries.c +++ b/tests/legacy/kernel/test_libs/src/libraries.c @@ -27,6 +27,7 @@ it guarantee that ALL functionality provided is working correctly. */ #include +#include #include #include @@ -229,7 +230,11 @@ int strcmp_test(void) int strncmp_test(void) { - strncpy(buffer, "eeeeeeeeeeee", BUFSIZE); + const char pattern[] = "eeeeeeeeeeee"; + + /* Note we don't want to count the final \0 that sizeof will */ + __ASSERT_NO_MSG(sizeof(pattern) - 1 > BUFSIZE); + memcpy(buffer, pattern, BUFSIZE); TC_PRINT("\tstrncmp 0 ...\t"); if (strncmp(buffer, "fffff", 0) != 0) {