Skip to content

Commit eb8997b

Browse files
committed
feat(opt): check duplicate sopt members for debug (#33)
1 parent 34d8437 commit eb8997b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cel/opt.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ static const void *argconv(const char *arg, int type)
136136
* - the sopt member is not allowed to have '?', '-', '+', '*', '=', and -1;
137137
* - the sopt member is allowed to have 0 only when the lopt member is not empty and a flag
138138
* variable provided;
139-
* - the lopt member is not allowed to contain '='; and
140-
* - if an option takes an option-argument, its type has to be specified.
139+
* - the lopt member is not allowed to contain '=';
140+
* - if an option takes an option-argument, its type has to be specified; and
141+
* - the table has no duplicate sopt member.
141142
*
142143
* chckvalid() is called by opt_init() if NDEBUG is not defined.
143144
*/
@@ -161,6 +162,11 @@ static void chckvalid(const opt_t *o)
161162
assert(!(o->flag == OPT_ARG_REQ || o->flag == OPT_ARG_OPT) ||
162163
(o->arg == OPT_TYPE_BOOL || o->arg == OPT_TYPE_INT || o->arg == OPT_TYPE_UINT ||
163164
o->arg == OPT_TYPE_REAL || o->arg == OPT_TYPE_STR));
165+
if (o->sopt && o->sopt <= UCHAR_MAX) {
166+
const opt_t *p;
167+
for (p = o + 1; p->lopt; p++)
168+
assert(o->sopt != p->sopt);
169+
}
164170
}
165171
}
166172

0 commit comments

Comments
 (0)