mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Minor optimization in parse_subsystem_tracepoint_event
@ 2009-12-06 18:25 Ulrich Drepper
  2009-12-07  7:10 ` Ingo Molnar
  2009-12-07  7:12 ` [tip:perf/urgent] perf tools: Optimize parse_subsystem_tracepoint_event() tip-bot for Ulrich Drepper
  0 siblings, 2 replies; 3+ messages in thread
From: Ulrich Drepper @ 2009-12-06 18:25 UTC (permalink / raw)
  To: a.p.zijlstra, fweisbec, jaswinderrajput, linux-kernel, mingo, paulus

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>

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 9e5dbd6..4c0bd3c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -467,7 +467,6 @@ 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, "..")
@@ -475,20 +474,12 @@ parse_subsystem_tracepoint_event(char *sys_name, char *flags)
 		    || !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;
 	}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Minor optimization in parse_subsystem_tracepoint_event
  2009-12-06 18:25 Minor optimization in parse_subsystem_tracepoint_event Ulrich Drepper
@ 2009-12-07  7:10 ` Ingo Molnar
  2009-12-07  7:12 ` [tip:perf/urgent] perf tools: Optimize parse_subsystem_tracepoint_event() tip-bot for Ulrich Drepper
  1 sibling, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2009-12-07  7:10 UTC (permalink / raw)
  To: Ulrich Drepper
  Cc: a.p.zijlstra, fweisbec, jaswinderrajput, linux-kernel, paulus


* Ulrich Drepper <drepper@redhat.com> wrote:

> 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>

Applied, thanks a lot Ulrich!

	Ingo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:perf/urgent] perf tools: Optimize parse_subsystem_tracepoint_event()
  2009-12-06 18:25 Minor optimization in parse_subsystem_tracepoint_event Ulrich Drepper
  2009-12-07  7:10 ` Ingo Molnar
@ 2009-12-07  7:12 ` tip-bot for Ulrich Drepper
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Ulrich Drepper @ 2009-12-07  7:12 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, drepper, hpa, mingo, tglx, mingo

Commit-ID:  180570fdb7a3c404b599f0a318c2ccf86e4827ed
Gitweb:     http://git.kernel.org/tip/180570fdb7a3c404b599f0a318c2ccf86e4827ed
Author:     Ulrich Drepper <drepper@redhat.com>
AuthorDate: Sun, 6 Dec 2009 13:25:30 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 7 Dec 2009 08:09:29 +0100

perf tools: Optimize parse_subsystem_tracepoint_event()

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>
---
 tools/perf/util/parse-events.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 448a13b..e5bc0fb 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -467,7 +467,6 @@ 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, "..")
@@ -475,20 +474,12 @@ parse_subsystem_tracepoint_event(char *sys_name, char *flags)
 		    || !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;
 	}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-07  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-06 18:25 Minor optimization in parse_subsystem_tracepoint_event Ulrich Drepper
2009-12-07  7:10 ` Ingo Molnar
2009-12-07  7:12 ` [tip:perf/urgent] perf tools: Optimize parse_subsystem_tracepoint_event() tip-bot for Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome