diff options
author | Karel Zak | 2013-03-13 13:04:02 +0100 |
---|---|---|
committer | Karel Zak | 2013-03-13 13:04:02 +0100 |
commit | 2c7bcdf868d25b934353d28c48c036a390cda0fb (patch) | |
tree | a98e8a0b7025aa377d79c242787fba253ce39091 /include/optutils.h | |
parent | fsfreeze: clean up usage(), add -V (diff) | |
download | kernel-qcow2-util-linux-2c7bcdf868d25b934353d28c48c036a390cda0fb.tar.gz kernel-qcow2-util-linux-2c7bcdf868d25b934353d28c48c036a390cda0fb.tar.xz kernel-qcow2-util-linux-2c7bcdf868d25b934353d28c48c036a390cda0fb.zip |
include/optutils: make collisions detection between options more robust
- don't rely on the correct ul_excl_t usage
- don't print --(null) for non-existing long options
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/optutils.h')
-rw-r--r-- | include/optutils.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/include/optutils.h b/include/optutils.h index 28a54b2ab..9177860bb 100644 --- a/include/optutils.h +++ b/include/optutils.h @@ -48,6 +48,9 @@ static inline const char *option_to_longopt(int c, const struct option *opts) * Note that the options in the group have to be in ASCII order (ABC..abc..) and * groups have to be also in ASCII order. * + * The maximal number of the options in the group is 15 (size of the array is + * 16, last is zero). + * * The current status of options is stored in excl_st array. The size of the array * must be the same as number of the groups in the ul_excl_t array. * @@ -73,12 +76,17 @@ static inline void err_exclusive_options( if (status[e] == 0) status[e] = c; else if (status[e] != c) { + size_t ct = 0; + fprintf(stderr, _("%s: options "), program_invocation_short_name); - for (op = excl[e]; *op; op++) { - if (opts) - fprintf(stderr, "--%s ", - option_to_longopt(*op, opts)); + + for (op = excl[e]; + ct + 1 < ARRAY_SIZE(excl[0]) && *op; + op++, ct++) { + const char *n = option_to_longopt(*op, opts); + if (n) + fprintf(stderr, "--%s ", n); else fprintf(stderr, "-%c ", *op); } |