Commit 051cdc3c authored by Ingo Molnar's avatar Ingo Molnar

perf help: Fix bug when there's no perf-* command around

main_cmds can be empty - fix util/help.c to handle this case
without segfaulting.
Reported-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
LKML-Reference: <new-submission>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent eed4dcd4
...@@ -298,7 +298,7 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old) ...@@ -298,7 +298,7 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
const char *help_unknown_cmd(const char *cmd) const char *help_unknown_cmd(const char *cmd)
{ {
int i, n, best_similarity = 0; int i, n = 0, best_similarity = 0;
struct cmdnames main_cmds, other_cmds; struct cmdnames main_cmds, other_cmds;
memset(&main_cmds, 0, sizeof(main_cmds)); memset(&main_cmds, 0, sizeof(main_cmds));
...@@ -315,6 +315,7 @@ const char *help_unknown_cmd(const char *cmd) ...@@ -315,6 +315,7 @@ const char *help_unknown_cmd(const char *cmd)
sizeof(main_cmds.names), cmdname_compare); sizeof(main_cmds.names), cmdname_compare);
uniq(&main_cmds); uniq(&main_cmds);
if (main_cmds.cnt) {
/* This reuses cmdname->len for similarity index */ /* This reuses cmdname->len for similarity index */
for (i = 0; i < main_cmds.cnt; ++i) for (i = 0; i < main_cmds.cnt; ++i)
main_cmds.names[i]->len = main_cmds.names[i]->len =
...@@ -327,8 +328,11 @@ const char *help_unknown_cmd(const char *cmd) ...@@ -327,8 +328,11 @@ const char *help_unknown_cmd(const char *cmd)
n = 1; n = 1;
while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len) while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
++n; ++n;
}
if (autocorrect && n == 1) { if (autocorrect && n == 1) {
const char *assumed = main_cmds.names[0]->name; const char *assumed = main_cmds.names[0]->name;
main_cmds.names[0] = NULL; main_cmds.names[0] = NULL;
clean_cmdnames(&main_cmds); clean_cmdnames(&main_cmds);
fprintf(stderr, "WARNING: You called a Git program named '%s', " fprintf(stderr, "WARNING: You called a Git program named '%s', "
...@@ -345,7 +349,7 @@ const char *help_unknown_cmd(const char *cmd) ...@@ -345,7 +349,7 @@ const char *help_unknown_cmd(const char *cmd)
fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd); fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd);
if (best_similarity < 6) { if (main_cmds.cnt && best_similarity < 6) {
fprintf(stderr, "\nDid you mean %s?\n", fprintf(stderr, "\nDid you mean %s?\n",
n < 2 ? "this": "one of these"); n < 2 ? "this": "one of these");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment