From 2c7bcdf868d25b934353d28c48c036a390cda0fb Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 13 Mar 2013 13:04:02 +0100 Subject: 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 --- include/optutils.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'include/optutils.h') 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); } -- cgit v1.2.3-55-g7522