diff options
author | Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | 2016-11-16 16:33:35 -0800 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2016-11-18 18:43:40 -0500 |
commit | 8173b881ba910a733deebc52b3e6bb0d83cf8cd2 (patch) | |
tree | 2dbad2f0c41af85dc898a8fc3bf54a08a2bba63f | |
parent | e7c091bba28d0c44da54632bfb8ca7670bfbc456 (diff) |
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 <inaky.perez-gonzalez@intel.com>
-rw-r--r-- | tests/legacy/kernel/test_libs/src/libraries.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/tests/legacy/kernel/test_libs/src/libraries.c b/tests/legacy/kernel/test_libs/src/libraries.c index e2262a253..4bb9f1eb0 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 <zephyr.h> +#include <misc/__assert.h> #include <tc_util.h> #include <limits.h> @@ -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) { |