Skip to content

Commit

Permalink
Abort on init with duplicate options (i.e. options with the same name).
Browse files Browse the repository at this point in the history
Reported by Thomas Adam.

Signed-off-by: Peter Rosin <peda@lysator.liu.se>
  • Loading branch information
peda-r committed Nov 25, 2015
1 parent a7337d1 commit 92a7887
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/confuse.c
Expand Up @@ -535,6 +535,20 @@ static void cfg_init_defaults(cfg_t *cfg)
int i;

for (i = 0; cfg->opts[i].name; i++) {
int j;
for (j = 0; j < i; ++j) {
if (strcmp(cfg->opts[i].name, cfg->opts[j].name))
continue;
/*
* There are two definitions of the same option name.
* What to do? It's a programming error and not an end
* user input error. Lets print a message and abort...
*/
fprintf(stderr, "duplicate option '%s' not allowed\n",
cfg->opts[i].name);
abort();
}

/* libConfuse doesn't handle default values for "simple" options */
if (cfg->opts[i].simple_value.ptr || is_set(CFGF_NODEFAULT, cfg->opts[i].flags))
continue;
Expand Down

0 comments on commit 92a7887

Please sign in to comment.