BASE: Check return value from strtol in DO_OPTION_INT macro
This commit is contained in:
parent
c52cc84912
commit
979fc29be6
1 changed files with 3 additions and 2 deletions
|
@ -267,8 +267,9 @@ void registerDefaults() {
|
||||||
#define DO_OPTION_INT(shortCmd, longCmd) \
|
#define DO_OPTION_INT(shortCmd, longCmd) \
|
||||||
DO_OPTION(shortCmd, longCmd) \
|
DO_OPTION(shortCmd, longCmd) \
|
||||||
char *endptr = 0; \
|
char *endptr = 0; \
|
||||||
strtol(option, &endptr, 0); \
|
long int retval = strtol(option, &endptr, 0); \
|
||||||
if (endptr == NULL || *endptr != 0) usage("--%s: Invalid number '%s'", longCmd, option);
|
if (endptr == NULL || *endptr != 0 || retval == 0 || retval == LONG_MAX || retval == LONG_MIN || errno == ERANGE) \
|
||||||
|
usage("--%s: Invalid number '%s'", longCmd, option);
|
||||||
|
|
||||||
// Use this for boolean options; this distinguishes between "-x" and "-X",
|
// Use this for boolean options; this distinguishes between "-x" and "-X",
|
||||||
// resp. between "--some-option" and "--no-some-option".
|
// resp. between "--some-option" and "--no-some-option".
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue