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>
This commit is contained in:
parent
ababbf7815
commit
324f8d7a41
1 changed files with 6 additions and 1 deletions
|
@ -27,6 +27,7 @@ it guarantee that ALL functionality provided is working correctly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
|
#include <misc/__assert.h>
|
||||||
#include <tc_util.h>
|
#include <tc_util.h>
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -229,7 +230,11 @@ int strcmp_test(void)
|
||||||
|
|
||||||
int strncmp_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");
|
TC_PRINT("\tstrncmp 0 ...\t");
|
||||||
if (strncmp(buffer, "fffff", 0) != 0) {
|
if (strncmp(buffer, "fffff", 0) != 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue