summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
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;
}
}