From: tip-bot for Arnaldo Carvalho de Melo <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: dbueso@suse.de, wangnan0@huawei.com,
linux-kernel@vger.kernel.org, jolsa@kernel.org, mingo@kernel.org,
hpa@zytor.com, jpoimboe@redhat.com, adrian.hunter@intel.com,
namhyung@kernel.org, dsahern@gmail.com, acme@redhat.com,
tglx@linutronix.de
Subject: [tip:perf/core] tools lib subcmd: Make it an error to pass a signed value to OPTION_UINTEGER
Date: Thu, 16 Feb 2017 12:00:02 -0800 [thread overview]
Message-ID: <tip-2mdn8s2raatyhz7tamrsz22r@git.kernel.org> (raw)
Commit-ID: b98897166280c4cfb9bc5a6c1b5682528eb4abff
Gitweb: http://git.kernel.org/tip/b98897166280c4cfb9bc5a6c1b5682528eb4abff
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Tue, 14 Feb 2017 13:55:40 -0300
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 14 Feb 2017 15:19:17 -0300
tools lib subcmd: Make it an error to pass a signed value to OPTION_UINTEGER
Options marked OPTION_UINTEGER or OPTION_U64 clearly indicates that an
unsigned value is expected, so just error out when a negative value is
passed, instead of returning something undesired to the tool.
E.g.:
# perf bench futex hash -t -4
# Running 'futex/hash' benchmark:
Error: switch `t' expects an unsigned numerical value
Usage: perf bench futex hash <options>
-t, --threads <n> Specify amount of threads
#
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Davidlohr Bueso <dbueso@suse.de>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-2mdn8s2raatyhz7tamrsz22r@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/subcmd/parse-options.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 8aad811..6bc2402 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -270,6 +270,8 @@ static int get_value(struct parse_opt_ctx_t *p,
}
if (get_arg(p, opt, flags, &arg))
return -1;
+ if (arg[0] == '-')
+ return opterror(opt, "expects an unsigned numerical value", flags);
*(unsigned int *)opt->value = strtol(arg, (char **)&s, 10);
if (*s)
return opterror(opt, "expects a numerical value", flags);
@@ -302,6 +304,8 @@ static int get_value(struct parse_opt_ctx_t *p,
}
if (get_arg(p, opt, flags, &arg))
return -1;
+ if (arg[0] == '-')
+ return opterror(opt, "expects an unsigned numerical value", flags);
*(u64 *)opt->value = strtoull(arg, (char **)&s, 10);
if (*s)
return opterror(opt, "expects a numerical value", flags);
reply other threads:[~2017-02-16 20:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=tip-2mdn8s2raatyhz7tamrsz22r@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=dbueso@suse.de \
--cc=dsahern@gmail.com \
--cc=hpa@zytor.com \
--cc=jolsa@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--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
Powered by JetHome