diff options
author | Keuin <[email protected]> | 2022-05-28 01:36:55 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-05-28 01:36:55 +0800 |
commit | b3200144a283c21326f5636873356b8c18ea78a3 (patch) | |
tree | 6e01ab5702db735afbd52b0dda966e562cfa5059 /main.c | |
parent | 3064ce6bfa8669f86c58ed74fb3f737671ec7fb1 (diff) |
Bugfix: strtol error handling is of no effect.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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; } } |