mirror of
https://github.com/ckolivas/lrzip.git
synced 2026-04-03 19:25:05 +02:00
Fail on unparsed characters after numeric arguments.
This commit is contained in:
parent
2713fef4b6
commit
9f544dc372
21
main.c
21
main.c
|
|
@ -316,6 +316,7 @@ int main(int argc, char *argv[])
|
||||||
int hours,minutes;
|
int hours,minutes;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
char *eptr, *av; /* for environment */
|
char *eptr, *av; /* for environment */
|
||||||
|
char *endptr = NULL;
|
||||||
|
|
||||||
control = &base_control;
|
control = &base_control;
|
||||||
|
|
||||||
|
|
@ -435,17 +436,23 @@ int main(int argc, char *argv[])
|
||||||
license();
|
license();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
control->compression_level = atoi(optarg);
|
control->compression_level = strtol(optarg, &endptr, 10);
|
||||||
if (control->compression_level < 1 || control->compression_level > 9)
|
if (control->compression_level < 1 || control->compression_level > 9)
|
||||||
failure("Invalid compression level (must be 1-9)\n");
|
failure("Invalid compression level (must be 1-9)\n");
|
||||||
|
if (*endptr)
|
||||||
|
failure("Extra characters after compression level: \'%s\'\n", endptr);
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
control->ramsize = atol(optarg) * 1024 * 1024 * 100;
|
control->ramsize = strtol(optarg, &endptr, 10) * 1024 * 1024 * 100;
|
||||||
|
if (*endptr)
|
||||||
|
failure("Extra characters after ramsize: \'%s\'\n", endptr);
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
control->nice_val = atoi(optarg);
|
control->nice_val = strtol(optarg, &endptr, 10);
|
||||||
if (control->nice_val < PRIO_MIN || control->nice_val > PRIO_MAX)
|
if (control->nice_val < PRIO_MIN || control->nice_val > PRIO_MAX)
|
||||||
failure("Invalid nice value (must be %d...%d)\n", PRIO_MIN, PRIO_MAX);
|
failure("Invalid nice value (must be %d...%d)\n", PRIO_MIN, PRIO_MAX);
|
||||||
|
if (*endptr)
|
||||||
|
failure("Extra characters after nice level: \'%s\'\n", endptr);
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
if (control->outdir)
|
if (control->outdir)
|
||||||
|
|
@ -468,9 +475,11 @@ int main(int argc, char *argv[])
|
||||||
strcat(control->outdir, "/");
|
strcat(control->outdir, "/");
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
control->threads = atoi(optarg);
|
control->threads = strtol(optarg, &endptr, 10);
|
||||||
if (control->threads < 1)
|
if (control->threads < 1)
|
||||||
failure("Must have at least one thread\n");
|
failure("Must have at least one thread\n");
|
||||||
|
if (*endptr)
|
||||||
|
failure("Extra characters after number of threads: \'%s\'\n", endptr);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
control->flags |= FLAG_SHOW_PROGRESS;
|
control->flags |= FLAG_SHOW_PROGRESS;
|
||||||
|
|
@ -519,9 +528,11 @@ int main(int argc, char *argv[])
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
control->window = atol(optarg);
|
control->window = strtol(optarg, &endptr, 10);
|
||||||
if (control->window < 1)
|
if (control->window < 1)
|
||||||
failure("Window must be positive\n");
|
failure("Window must be positive\n");
|
||||||
|
if (*endptr)
|
||||||
|
failure("Extra characters after window size: \'%s\'\n", endptr);
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
case '2':
|
case '2':
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue