From 2dce92236b9fe0a9398287ac7c62f2f4e67d53b6 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Fri, 22 Nov 2024 23:00:55 +0100 Subject: libc: Fix bugs in strto(u)l(l) --- userland/libc/stdlib/strtol.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'userland/libc/stdlib/strtol.c') diff --git a/userland/libc/stdlib/strtol.c b/userland/libc/stdlib/strtol.c index 4a1e189..460dedd 100644 --- a/userland/libc/stdlib/strtol.c +++ b/userland/libc/stdlib/strtol.c @@ -44,12 +44,15 @@ long strtol(const char *str, char **restrict endptr, int base) { if (2 <= base && 36 >= base) { for (; *str; str++) { + int val = get_value(*str, base); + if (-1 == val) { + break; + } if (ret_value > LONG_MAX / base) { errno = ERANGE; return LONG_MAX; } ret_value *= base; - int val = get_value(*str, base); if (ret_value > LONG_MAX - val) { errno = ERANGE; return LONG_MAX; -- cgit v1.2.3