summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-12-02 00:08:57 -0600
committerJunio C Hamano <gitster@pobox.com>2010-12-07 14:19:10 -0800
commit5c400ed2e05070d79b6cd9438ff5607ec0a83589 (patch)
tree982df752c16b4eb892154585fd403d5530e99c05 /parse-options.c
parenta02dd4ff7dd79eb6aa39b00c90c293e3c3d10b4c (diff)
downloadgit-5c400ed2e05070d79b6cd9438ff5607ec0a83589.tar.gz
parse-options: sanity check PARSE_OPT_NOARG flag
Some option types cannot use an argument --- boolean options that would set a bit or flag or increment a counter, for example. If configured in the flag word to accept an argument anyway, the result is an argument that is advertised in "program -h" output only to be rejected by parse-options::get_value. Luckily all current users of these option types use PARSE_OPT_NOARG and do not use PARSE_OPT_OPTARG. Add a check to ensure that that remains true. The check is run once for each invocation of parse_option_start(). Improved-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/parse-options.c b/parse-options.c
index 9ff9acaabf..79c56f32f9 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -330,6 +330,19 @@ static void parse_options_check(const struct option *opts)
opts->long_name))
err |= optbug(opts, "uses feature "
"not supported for dashless options");
+ switch (opts->type) {
+ case OPTION_BOOLEAN:
+ case OPTION_BIT:
+ case OPTION_NEGBIT:
+ case OPTION_SET_INT:
+ case OPTION_SET_PTR:
+ case OPTION_NUMBER:
+ if ((opts->flags & PARSE_OPT_OPTARG) ||
+ !(opts->flags & PARSE_OPT_NOARG))
+ err |= optbug(opts, "should not accept an argument");
+ default:
+ ; /* ok. (usually accepts an argument) */
+ }
}
if (err)
exit(128);