summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-05-28 01:36:55 +0800
committerKeuin <[email protected]>2022-05-28 01:36:55 +0800
commitb3200144a283c21326f5636873356b8c18ea78a3 (patch)
tree6e01ab5702db735afbd52b0dda966e562cfa5059 /main.c
parent3064ce6bfa8669f86c58ed74fb3f737671ec7fb1 (diff)
Bugfix: strtol error handling is of no effect.
Diffstat (limited to 'main.c')
-rw-r--r--main.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/main.c b/main.c
index 37f5a0a..b632cf8 100644
--- a/main.c
+++ b/main.c
@@ -308,11 +308,16 @@ int main(int argc, char *argv[]) {
goto USAGE;
}
errno = 0;
- threads = strtol(argv[i + 1], NULL, 10);
- if (errno) {
+ char *end;
+ long val = strtol(argv[i + 1], &end, 10);
+ if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
+ (errno != 0 && val == 0) ||
+ end == argv[i + 1] ||
+ val <= 0) {
printf("Invalid thread count number.\n");
goto USAGE; /* invalid integer */
}
+ threads = val;
break;
}
}