Skip to contentSkip to conversation

perf help: Remove needless use of strncpy()

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Dec 14, 2018 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  b8990e60c7a5643185bf751cae9cd58bcb8b6474
Gitweb:     https://git.kernel.org/tip/b8990e60c7a5643185bf751cae9cd58bcb8b6474
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Thu, 6 Dec 2018 11:20:21 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 6 Dec 2018 16:41:15 -0300

perf help: Remove needless use of strncpy()

Since we make sure the destination buffer has at least strlen(orig) + 1, no need to do a strncpy(dest, orig, strlen(orig)), just use strcpy(dest, orig).

This silences this gcc 8.2 warning on Alpine Linux:

In function 'add_man_viewer',
inlined from 'perf_help_config' at builtin-help.c:284:3:
builtin-help.c:192:2: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]

    strncpy((*p)->name, name, len);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  builtin-help.c: In function 'perf_help_config':
  builtin-help.c:187:15: note: length computed here
    size_t len = strlen(name);
                 ^~~~~~~~~~~~
Cc Adrian Hunter <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Fixes 078006012401 ("perf_counter tools: add in basic glue from Git")
---
 tools/perf/builtin-help.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-help.c +1 -1
index 1c41b4eaf73c..3d29d0524a89 100644
@@ -189,7 +189,7 @@ static void add_man_viewer(const char *name)
 	while (*p)
 		p = &((*p)->next);
 	*p = zalloc(sizeof(**p) + len + 1);
-	strncpy((*p)->name, name, len);
+	strcpy((*p)->name, name);
 }
 
 static int supported_man_viewer(const char *name, size_t len)