Skip to content

Commit

Permalink
Show recognized names in message for bad option value
Browse files Browse the repository at this point in the history
  • Loading branch information
gavtroy authored and flyingmutant committed Sep 14, 2024
1 parent 67cbbe2 commit 59bfea1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion options.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ int parse_enum(const char *buf, int minval, int maxval, const char * const names
{
long int tmp;
int i;
GBUF(names_buf);

if (str_to_int(buf, &tmp) == 0) {
if (tmp < minval || tmp > maxval)
Expand All @@ -206,7 +207,13 @@ int parse_enum(const char *buf, int minval, int maxval, const char * const names
}
}
err:
error_msg("name or integer in range %d..%d expected", minval, maxval);
for (i = 0; names[i]; i++) {
if (i)
gbuf_add_str(&names_buf, ", ");
gbuf_add_str(&names_buf, names[i]);
}
error_msg("expected [%d..%d] or [%s]", minval, maxval, names_buf.buffer);
gbuf_free(&names_buf);
return 0;
}

Expand Down

0 comments on commit 59bfea1

Please sign in to comment.