提交 cfed95a6 编写于 作者: V Vincent Legoll 提交者: Ingo Molnar

perf tools: 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: NVincent Legoll <vincent.legoll@gmail.com>
Cc: Linus Torvalds <torvalds@osdl.org>
LKML-Reference: <4727185d0910130118m5387058dndb02ac9b384af9f0@mail.gmail.com>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
上级 9dbdd6c4
...@@ -89,8 +89,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged) ...@@ -89,8 +89,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
/* /*
* Check remaining flags. * Check remaining flags.
*/ */
if (!prefixcmp(cmd, "--exec-path")) { if (!prefixcmp(cmd, CMD_EXEC_PATH)) {
cmd += 11; cmd += strlen(CMD_EXEC_PATH);
if (*cmd == '=') if (*cmd == '=')
perf_set_argv_exec_path(cmd + 1); perf_set_argv_exec_path(cmd + 1);
else { else {
...@@ -117,8 +117,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged) ...@@ -117,8 +117,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
(*argv)++; (*argv)++;
(*argc)--; (*argc)--;
handled++; handled++;
} else if (!prefixcmp(cmd, "--perf-dir=")) { } else if (!prefixcmp(cmd, CMD_PERF_DIR)) {
setenv(PERF_DIR_ENVIRONMENT, cmd + 10, 1); setenv(PERF_DIR_ENVIRONMENT, cmd + strlen(CMD_PERF_DIR), 1);
if (envchanged) if (envchanged)
*envchanged = 1; *envchanged = 1;
} else if (!strcmp(cmd, "--work-tree")) { } else if (!strcmp(cmd, "--work-tree")) {
...@@ -131,8 +131,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged) ...@@ -131,8 +131,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
*envchanged = 1; *envchanged = 1;
(*argv)++; (*argv)++;
(*argc)--; (*argc)--;
} else if (!prefixcmp(cmd, "--work-tree=")) { } else if (!prefixcmp(cmd, CMD_WORK_TREE)) {
setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + 12, 1); setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + strlen(CMD_WORK_TREE), 1);
if (envchanged) if (envchanged)
*envchanged = 1; *envchanged = 1;
} else if (!strcmp(cmd, "--debugfs-dir")) { } else if (!strcmp(cmd, "--debugfs-dir")) {
...@@ -146,8 +146,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged) ...@@ -146,8 +146,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
*envchanged = 1; *envchanged = 1;
(*argv)++; (*argv)++;
(*argc)--; (*argc)--;
} else if (!prefixcmp(cmd, "--debugfs-dir=")) { } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
strncpy(debugfs_mntpt, cmd + 14, MAXPATHLEN); strncpy(debugfs_mntpt, cmd + strlen(CMD_DEBUGFS_DIR), MAXPATHLEN);
debugfs_mntpt[MAXPATHLEN - 1] = '\0'; debugfs_mntpt[MAXPATHLEN - 1] = '\0';
if (envchanged) if (envchanged)
*envchanged = 1; *envchanged = 1;
......
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
#include "strbuf.h" #include "strbuf.h"
#include "../perf.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_DIR_ENVIRONMENT "PERF_DIR"
#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE" #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册