From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756271AbcB0JkD (ORCPT ); Sat, 27 Feb 2016 04:40:03 -0500 Received: from torg.zytor.com ([198.137.202.12]:39020 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756036AbcB0Jj7 (ORCPT ); Sat, 27 Feb 2016 04:39:59 -0500 Date: Sat, 27 Feb 2016 01:39:37 -0800 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, acme@redhat.com, tglx@linutronix.de, wangnan0@huawei.com, adrian.hunter@intel.com, namhyung@kernel.org, mingo@kernel.org Reply-To: acme@redhat.com, tglx@linutronix.de, jolsa@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, adrian.hunter@intel.com, wangnan0@huawei.com, namhyung@kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Use asprintf() for simple string formatting/allocation Git-Commit-ID: 5104ffb229c357d9672344126040721e5dc4cc7b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 5104ffb229c357d9672344126040721e5dc4cc7b Gitweb: http://git.kernel.org/tip/5104ffb229c357d9672344126040721e5dc4cc7b Author: Arnaldo Carvalho de Melo AuthorDate: Thu, 25 Feb 2016 10:14:50 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 25 Feb 2016 10:14:50 -0300 perf tools: Use asprintf() for simple string formatting/allocation No need to use strbuf there, its just a simple alloc+formatting, which asprintf does just fine. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-6q6cxfhk8c8ypg3tfpo0i2iy@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/perf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 144047c..f632119 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -454,11 +454,12 @@ static void handle_internal_command(int argc, const char **argv) static void execv_dashed_external(const char **argv) { - struct strbuf cmd = STRBUF_INIT; + char *cmd; const char *tmp; int status; - strbuf_addf(&cmd, "perf-%s", argv[0]); + if (asprintf(&cmd, "perf-%s", argv[0]) < 0) + goto do_die; /* * argv[0] must be the perf command, but the argv array @@ -467,7 +468,7 @@ static void execv_dashed_external(const char **argv) * restore it on error. */ tmp = argv[0]; - argv[0] = cmd.buf; + argv[0] = cmd; /* * if we fail because the command is not found, it is @@ -475,15 +476,16 @@ static void execv_dashed_external(const char **argv) */ status = run_command_v_opt(argv, 0); if (status != -ERR_RUN_COMMAND_EXEC) { - if (IS_RUN_COMMAND_ERR(status)) + if (IS_RUN_COMMAND_ERR(status)) { +do_die: die("unable to run '%s'", argv[0]); + } exit(-status); } errno = ENOENT; /* as if we called execvp */ argv[0] = tmp; - - strbuf_release(&cmd); + zfree(&cmd); } static int run_argv(int *argcp, const char ***argv)