From: Vincent Legoll <vincent.legoll@gmail.com>
To: Linux Kernel ML <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@osdl.org>
Subject: [PATCH] [PERF] do not manually count string lengths
Date: Tue, 13 Oct 2009 10:18:16 +0200 [thread overview]
Message-ID: <4727185d0910130118m5387058dndb02ac9b384af9f0@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 246 bytes --]
Hello,
here is a small patch to the perf tool to use strlen & macros
instead of manually counting string lengths.
I didn't find mention of any maintainer for the tool...
Please advise if I should submit this in another way
--
Vincent Legoll
[-- Attachment #2: 0001-Do-not-manually-count-string-lengths.patch --]
[-- Type: text/x-diff, Size: 2852 bytes --]
From 1c8755d5753f913fe4c02a9d0ee7fa51fda0c002 Mon Sep 17 00:00:00 2001
From: Vincent Legoll <vincent.legoll@gmail.com>
Date: Tue, 13 Oct 2009 10:04:54 +0200
Subject: [PATCH] Do not manually count string lengths
Use strlen & macros instead of manually counting string lengths
as this is error prone and may lend to bugs.
Signed-off-by: Vincent Legoll <vincent.legoll@gmail.com>
---
tools/perf/perf.c | 16 ++++++++--------
tools/perf/util/cache.h | 5 +++++
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 19fc7fe..624e62d 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -89,8 +89,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
/*
* Check remaining flags.
*/
- if (!prefixcmp(cmd, "--exec-path")) {
- cmd += 11;
+ if (!prefixcmp(cmd, CMD_EXEC_PATH)) {
+ cmd += strlen(CMD_EXEC_PATH);
if (*cmd == '=')
perf_set_argv_exec_path(cmd + 1);
else {
@@ -117,8 +117,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
(*argv)++;
(*argc)--;
handled++;
- } else if (!prefixcmp(cmd, "--perf-dir=")) {
- setenv(PERF_DIR_ENVIRONMENT, cmd + 10, 1);
+ } else if (!prefixcmp(cmd, CMD_PERF_DIR)) {
+ setenv(PERF_DIR_ENVIRONMENT, cmd + strlen(CMD_PERF_DIR), 1);
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--work-tree")) {
@@ -131,8 +131,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
*envchanged = 1;
(*argv)++;
(*argc)--;
- } else if (!prefixcmp(cmd, "--work-tree=")) {
- setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + 12, 1);
+ } else if (!prefixcmp(cmd, CMD_WORK_TREE)) {
+ setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + strlen(CMD_WORK_TREE), 1);
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--debugfs-dir")) {
@@ -146,8 +146,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
*envchanged = 1;
(*argv)++;
(*argc)--;
- } else if (!prefixcmp(cmd, "--debugfs-dir=")) {
- strncpy(debugfs_mntpt, cmd + 14, MAXPATHLEN);
+ } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
+ strncpy(debugfs_mntpt, cmd + strlen(CMD_DEBUGFS_DIR), MAXPATHLEN);
debugfs_mntpt[MAXPATHLEN - 1] = '\0';
if (envchanged)
*envchanged = 1;
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 6f8ea9d..c6deebc 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -5,6 +5,11 @@
#include "strbuf.h"
#include "../perf.h"
+#define CMD_EXEC_PATH "--exec-path"
+#define CMD_PERF_DIR "--perf-dir="
+#define CMD_WORK_TREE "--work-tree="
+#define CMD_DEBUGFS_DIR "--debugfs-dir="
+
#define PERF_DIR_ENVIRONMENT "PERF_DIR"
#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
--
1.6.0.4
next reply other threads:[~2009-10-13 8:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-13 8:18 Vincent Legoll [this message]
2009-10-13 10:01 ` Ingo Molnar
2009-10-13 11:51 ` Vincent Legoll
2009-10-13 12:27 ` Ingo Molnar
2009-10-13 12:48 ` Vincent Legoll
2009-10-13 12:58 ` Pekka Enberg
2009-10-13 13:34 ` [tip:perf/urgent] perf events: Update MAINTAINERS entry file patterns tip-bot for Vincent Legoll
2009-10-13 10:35 ` [tip:perf/core] perf tools: Do not manually count string lengths tip-bot for Vincent Legoll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4727185d0910130118m5387058dndb02ac9b384af9f0@mail.gmail.com \
--to=vincent.legoll@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®