lkml.org 
[lkml]   [2014]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] tools: perf: util: parse-events.c: Cleaning up missing null-terminate after strncpy call
On Wed, Jun 04, 2014 at 11:46:18PM +0200, Rickard Strandqvist wrote:
> Added a guaranteed null-terminate after call to strncpy.
>
> This was partly found using a static code analysis program called cppcheck.

Should just stop using strncpy. strncpy semantics don't make any
sense at all, and it's inefficient. I would just snprintf here

-Andi

>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
> tools/perf/util/parse-events.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 1e15df1..fad2976 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -1216,8 +1216,10 @@ static void print_symbol_events(const char *event_glob, unsigned type,
>
> if (strlen(syms->alias))
> snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
> - else
> + else {
> strncpy(name, syms->symbol, MAX_NAME_LEN);
> + name[sizeof(name) - 1] = '\0';
> + }
>
> printf(" %-50s [%s]\n", name, event_type_descriptors[type]);
>
> --
> 1.7.10.4
>

--
ak@linux.intel.com -- Speaking for myself only


\
 
 \ /
  Last update: 2014-06-07 01:01    [W:0.073 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site