[PATCH] tools/x86/kcpuid: Replace deprecated strncpy() with strscpy()

From: feng.wei8
Date: Mon Mar 17 2025 - 03:32:56 EST


From: FengWei <feng.wei8@xxxxxxxxxx>

strncpy() is deprecated for NUL-terminated destination buffers. Use
strscpy() instead and remove the manual NUL-termination.

Signed-off-by: FengWei <feng.wei8@xxxxxxxxxx>
---
tools/arch/x86/kcpuid/kcpuid.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index 1b25c0a95d3f..23a8fde2e203 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -312,8 +312,7 @@ static int parse_line(char *line)
if (line[0] == '#' || line[0] == '\n')
return 0;

- strncpy(buffer, line, 511);
- buffer[511] = 0;
+ strscpy(buffer, line, 511);
str = buffer;
for (i = 0; i < 5; i++) {
tokens[i] = strtok(str, ",");
--
2.25.1