diff options
author | Anton Kling <anton@kling.gg> | 2024-11-22 23:00:55 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-11-22 23:00:55 +0100 |
commit | 2dce92236b9fe0a9398287ac7c62f2f4e67d53b6 (patch) | |
tree | 2e03ae3d27fabd7004cb396c23debfc74e64e3b7 /userland/libc/stdlib/strtol.c | |
parent | 597ac49280e8ab59e779c5d33ad266b477208293 (diff) |
libc: Fix bugs in strto(u)l(l)
Diffstat (limited to 'userland/libc/stdlib/strtol.c')
-rw-r--r-- | userland/libc/stdlib/strtol.c | 5 |
1 files changed, 4 insertions, 1 deletions
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; |