From ed1794ffbf6a1ab1dfe40147776a616b054b3170 Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 20 Aug 2025 13:18:45 +0200 Subject: [PATCH] improve number parsing in `opts.c` --- src/opts.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/opts.c b/src/opts.c index 0674e7d..7129201 100644 --- a/src/opts.c +++ b/src/opts.c @@ -1,5 +1,6 @@ #include "opts.h" +#include #include #include #include @@ -36,8 +37,11 @@ u8 getoptions(int argc, char *const *argv, int *ncpus) { } if (optind < argc) { + char *end; char *num = argv[optind]; - *ncpus = atoi(num); + *ncpus = strtol(num, &end, 0); + if (errno || end == num || *end != '\0') + fatal("failed to parse numeric value from string '%s'", num); } else if (opts & OPT_LIST_CORES) { *ncpus = -1; } else