diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-14 11:55:40 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-14 13:19:17 -0500 |
commit | b98897166280c4cfb9bc5a6c1b5682528eb4abff (patch) | |
tree | fefdb084b833c96bffc26a48224903c26bc3f395 /tools/lib | |
parent | 49b3cd306e60b9d889c775cb2ebb709f80dd8ae9 (diff) |
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>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/subcmd/parse-options.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c index 8aad81151d50..6bc24025d054 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, | |||
270 | } | 270 | } |
271 | if (get_arg(p, opt, flags, &arg)) | 271 | if (get_arg(p, opt, flags, &arg)) |
272 | return -1; | 272 | return -1; |
273 | if (arg[0] == '-') | ||
274 | return opterror(opt, "expects an unsigned numerical value", flags); | ||
273 | *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10); | 275 | *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10); |
274 | if (*s) | 276 | if (*s) |
275 | return opterror(opt, "expects a numerical value", flags); | 277 | return opterror(opt, "expects a numerical value", flags); |
@@ -302,6 +304,8 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
302 | } | 304 | } |
303 | if (get_arg(p, opt, flags, &arg)) | 305 | if (get_arg(p, opt, flags, &arg)) |
304 | return -1; | 306 | return -1; |
307 | if (arg[0] == '-') | ||
308 | return opterror(opt, "expects an unsigned numerical value", flags); | ||
305 | *(u64 *)opt->value = strtoull(arg, (char **)&s, 10); | 309 | *(u64 *)opt->value = strtoull(arg, (char **)&s, 10); |
306 | if (*s) | 310 | if (*s) |
307 | return opterror(opt, "expects a numerical value", flags); | 311 | return opterror(opt, "expects a numerical value", flags); |