Skip to content

Commit

Permalink
perf tools: Optimize parse_subsystem_tracepoint_event()
Browse files Browse the repository at this point in the history
Uses of strcat are almost always signs that someone is too lazy
to think about the code a bit more carefully.  One always has to
know about the lengths of the strings involved to avoid buffer
overflows.

This is one case where the size of the object code for me is
reduced by 38 bytes.  The code should also be faster, especially
if flags is non-NULL.

Signed-off-by: Ulrich Drepper <drepper@redhat.com>
Cc: a.p.zijlstra@chello.nl
Cc: fweisbec@gmail.com
Cc: jaswinderrajput@gmail.com
Cc: paulus@samba.org
LKML-Reference: <200912061825.nB6IPUa1023306@hs20-bc2-1.build.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Ulrich Drepper authored and Ingo Molnar committed Dec 7, 2009
1 parent 67a6259 commit 180570f
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,28 +467,19 @@ parse_subsystem_tracepoint_event(char *sys_name, char *flags)
while ((evt_ent = readdir(evt_dir))) {
char event_opt[MAX_EVOPT_LEN + 1];
int len;
unsigned int rem = MAX_EVOPT_LEN;

if (!strcmp(evt_ent->d_name, ".")
|| !strcmp(evt_ent->d_name, "..")
|| !strcmp(evt_ent->d_name, "enable")
|| !strcmp(evt_ent->d_name, "filter"))
continue;

len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s", sys_name,
evt_ent->d_name);
len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s%s%s", sys_name,
evt_ent->d_name, flags ? ":" : "",
flags ?: "");
if (len < 0)
return EVT_FAILED;

rem -= len;
if (flags) {
if (rem < strlen(flags) + 1)
return EVT_FAILED;

strcat(event_opt, ":");
strcat(event_opt, flags);
}

if (parse_events(NULL, event_opt, 0))
return EVT_FAILED;
}
Expand Down

0 comments on commit 180570f

Please sign in to comment.