From b3200144a283c21326f5636873356b8c18ea78a3 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 28 May 2022 01:36:55 +0800 Subject: Bugfix: strtol error handling is of no effect. --- main.c | 9 +++++++-- 1 file 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; } } -- cgit v1.2.3