Skip to content

Commit 3ef3a05

Browse files
arndbakpm00
authored andcommitted
test_hexdump: avoid string truncation warning
gcc can warn when a string is too long to fit into the strncpy() destination buffer, as it is here depending on the function arguments: inlined from 'test_hexdump_prepare_test.constprop' at /home/arnd/arm-soc/lib/test_hexdump.c:116:3: include/linux/fortify-string.h:108:33: error: '__builtin_strncpy' output truncated copying between 0 and 32 bytes from a string of length 32 [-Werror=stringop-truncation] 108 | #define __underlying_strncpy __builtin_strncpy | ^ include/linux/fortify-string.h:187:16: note: in expansion of macro '__underlying_strncpy' 187 | return __underlying_strncpy(p, q, size); | ^~~~~~~~~~~~~~~~~~~~ The intention here is to copy exactly 'l' bytes without any padding or NUL-termination, so the most logical change is to use memcpy(), just as a previous change adapted the other output from strncpy() to memcpy(). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Arnd Bergmann <[email protected]> Acked-by: Justin Stitt <[email protected]> Cc: Alexey Starikovskiy <[email protected]> Cc: Bob Moore <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Len Brown <[email protected]> Cc: Lin Ming <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nicolas Schier <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: "Richard Russon (FlatCap)" <[email protected]> Cc: Steven Rostedt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b8cb324 commit 3ef3a05

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/test_hexdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void __init test_hexdump_prepare_test(size_t len, int rowsize,
113113
*p++ = ' ';
114114
} while (p < test + rs * 2 + rs / gs + 1);
115115

116-
strncpy(p, data_a, l);
116+
memcpy(p, data_a, l);
117117
p += l;
118118
}
119119

0 commit comments

Comments
 (0)