Improve robustness of parsing the --debug argument
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
c9c56be396
commit
5121108542
1 changed files with 12 additions and 1 deletions
|
@ -409,7 +409,18 @@ static int parsearg_global(int opt)
|
|||
* here, error and warning are set in config_new, though perhaps a
|
||||
* --quiet option will remove these later */
|
||||
if(optarg) {
|
||||
unsigned short debug = (unsigned short)atoi(optarg);
|
||||
char *endptr;
|
||||
long debug;
|
||||
|
||||
errno = 0;
|
||||
debug = strtol(optarg, &endptr, 10);
|
||||
|
||||
if(errno == ERANGE || endptr == optarg || *endptr != '\0') {
|
||||
pm_printf(ALPM_LOG_ERROR, _("'%s' is not a valid debug level\n"),
|
||||
optarg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch(debug) {
|
||||
case 2:
|
||||
config->logmask |= ALPM_LOG_FUNCTION;
|
||||
|
|
Loading…
Add table
Reference in a new issue