Skip to content

Commit

Permalink
Show error on init with duplicate options (i.e. opts 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 def1c7a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/confuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,25 @@ 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 (is_set(CFGF_NOCASE, cfg->opts[i].flags | cfg->opts[j].flags)) {
if (strcasecmp(cfg->opts[i].name, cfg->opts[j].name))
continue;
} else {
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...
*/
cfg_error(cfg, _("duplicate option '%s' not allowed"),
cfg->opts[i].name);
break;
}

/* 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 def1c7a

Please sign in to comment.