commit a238f897eee4be2fb561f4bbe33ed6aaa61b54ba
parent 6c28dec4a111ad73f8ac17c89305a951371f765d
Author: Sebastiano Tronto <sebastiano.tronto@gmail.com>
Date: Fri, 10 Dec 2021 18:18:21 +0100
Fixed segfault when passing malformed command arguments to solve
Diffstat:
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/commands.c b/src/commands.c
@@ -130,7 +130,7 @@ solve_parse_args(int c, char **v)
a->opts->print_number = true;
for (i = 0; i < c; i++) {
- if (!strcmp(v[i], "-m")) {
+ if (!strcmp(v[i], "-m") && i+1 < c) {
val = strtol(v[++i], NULL, 10);
if (val < 0 || val > 100) {
fprintf(stderr,
@@ -139,7 +139,7 @@ solve_parse_args(int c, char **v)
return a;
}
a->opts->min_moves = val;
- } else if (!strcmp(v[i], "-M")) {
+ } else if (!strcmp(v[i], "-M") && i+1 < c) {
val = strtol(v[++i], NULL, 10);
if (val < 0 || val > 100) {
fprintf(stderr,
@@ -148,7 +148,7 @@ solve_parse_args(int c, char **v)
return a;
}
a->opts->max_moves = val;
- } else if (!strcmp(v[i], "-t")) {
+ } else if (!strcmp(v[i], "-t") && i+1 < c) {
val = strtol(v[++i], NULL, 10);
if (val < 1 || val > 64) {
fprintf(stderr,
@@ -157,7 +157,7 @@ solve_parse_args(int c, char **v)
return a;
}
a->opts->nthreads = val;
- } else if (!strcmp(v[i], "-s")) {
+ } else if (!strcmp(v[i], "-s") && i+1 < c) {
val = strtol(v[++i], NULL, 10);
if (val < 1 || val > 1000000) {
fprintf(stderr,