linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yunlong Song <yunlong.song@huawei.com>
To: <a.p.zijlstra@chello.nl>, <paulus@samba.org>, <mingo@redhat.com>,
	<acme@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <wangnan0@huawei.com>
Subject: [PATCH 4/7] perf list: fix a bug of segmentation fault
Date: Fri, 13 Feb 2015 21:11:52 +0800	[thread overview]
Message-ID: <1423833115-11199-5-git-send-email-yunlong.song@huawei.com> (raw)
In-Reply-To: <1423833115-11199-1-git-send-email-yunlong.song@huawei.com>

Fix the 'segmentation fault' bug of 'perf list --list-cmds', which
also happens in other cases (e.g. record, report ...). This bug happens
when there are no cmds to list at all.

Example
Before this patch:
$perf list --list-cmds
Segmentation fault
$

After this patch:
$perf list --list-cmds
$

As shown above, the result prints nothing rather than a segmentation
fault. The null result means 'perf list' has no cmds to display at this
time.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/util/parse-options.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 4a015f7..4ee9a86 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -510,8 +510,10 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
 		}
 		exit(130);
 	case PARSE_OPT_LIST_SUBCMDS:
-		for (int i = 0; subcommands[i]; i++)
-			printf("%s ", subcommands[i]);
+		if (subcommands) {
+			for (int i = 0; subcommands[i]; i++)
+				printf("%s ", subcommands[i]);
+		}
 		exit(130);
 	default: /* PARSE_OPT_UNKNOWN */
 		if (ctx.argv[0][1] == '-') {
-- 
1.8.5.5


  parent reply	other threads:[~2015-02-13 13:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-13 13:11 [PATCH 0/7] perf list: make some improvements and fixes Yunlong Song
2015-02-13 13:11 ` [PATCH 1/7] perf list: clean up the printing functions of hardware/software events Yunlong Song
2015-02-13 13:11 ` [PATCH 2/7] perf list: sort the output of 'perf list' to view more clearly Yunlong Song
2015-02-13 14:45   ` Arnaldo Carvalho de Melo
2015-02-13 14:49     ` Arnaldo Carvalho de Melo
2015-02-15 10:19       ` Yunlong Song
2015-02-15 10:11     ` Yunlong Song
2015-02-13 13:11 ` [PATCH 3/7] perf list: fix some inaccuracy problem when parsing the argument Yunlong Song
2015-02-13 13:11 ` Yunlong Song [this message]
2015-02-18 18:41   ` [tip:perf/core] perf tools: Fix a bug of segmentation fault tip-bot for Yunlong Song
2015-02-13 13:11 ` [PATCH 5/7] perf list: avoid confusion of perf output and the next command prompt Yunlong Song
2015-02-13 14:52   ` Arnaldo Carvalho de Melo
2015-02-15 10:01     ` Yunlong Song
2015-02-13 13:11 ` [PATCH 6/7] perf list: extend raw-dump to certain kind of events Yunlong Song
2015-02-13 14:55   ` Arnaldo Carvalho de Melo
2015-02-15 10:05     ` Yunlong Song
2015-02-13 13:11 ` [PATCH 7/7] perf list: place the guiding text in its right position Yunlong Song
2015-02-18 18:42   ` [tip:perf/core] perf list: Place the header " tip-bot for Yunlong Song

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=1423833115-11199-5-git-send-email-yunlong.song@huawei.com \
    --to=yunlong.song@huawei.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=wangnan0@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).