test_hexdump: Replace strncpy with memcpy
PATCH 1/1 test_hexdump: Replace strncpy with memcpy
gcc 8.1.0 complains:
lib/test_hexdump.c:84:3: warning:
'strncpy' output truncated before terminating nul copying as many bytes from a string as its lengthlib/test_hexdump.c:82:19: note: length computed here
Using strncpy() is indeed less than perfect since the length of data to be copied has already been determined with strlen(). Replace strncpy() with memcpy() to address the warning and optimize the code a little.
--- lib/test_hexdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_hexdump.c +1 -1
@@ -81,7 +81,7 @@ static void __init test_hexdump_prepare_test(size_t len, int rowsize,const char *q = *result++;size_t amount =strlen (q); -strncpy (p, q, amount); +memcpy (p, q, amount); p += amount; *p++ =' ' ;
Signature · 1 line
2.7.4
Quoted 11 lines · Guenter Roeck
gcc 8.1.0 complains:
lib/test_hexdump.c:84:3: warning:
'strncpy' output truncated before terminating nul copying as many bytes from a string as its lengthlib/test_hexdump.c:82:19: note: length computed hereUsing
strncpy()is indeed less than perfect since the length of data to be copied has already been determined withstrlen(). Replacestrncpy()withmemcpy()to address the warning and optimize the code a little.
If it helps for some reason I'm not objecting to switch to memcpy().
Quoted 21 lines
Signed-off-by Guenter Roeck <[email protected]>--- lib/test_hexdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/test_hexdump.c +1
-2@@ -81,7 +81,7 @@ static void __init test_hexdump_prepare_test(size_t len, int rowsize,const char *q = *result++;size_t amount =strlen (q); -strncpy (p, q, amount); +memcpy (p, q, amount); p += amount; *p++ =' ' ; --2.7.4
Signature · 2 lines
With Best Regards, Andy Shevchenko