From 6b1ed26e6aaaacfe83ee0a26ec79b378aa7e376b Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Tue, 12 May 2020 13:24:25 +0430 Subject: [PATCH] LibC: Always assign the offset pointer to endptr in strto{u,}ll() This patch makes strto{u,}l{l,}() behave more to-spec about endptr. "If endptr is not NULL, strtoull stores the address of the first invalid character in *endptr." --- Libraries/LibC/stdlib.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp index 263ad272b9..139f484475 100644 --- a/Libraries/LibC/stdlib.cpp +++ b/Libraries/LibC/stdlib.cpp @@ -929,6 +929,9 @@ long long strtoll(const char* str, char** endptr, int base) return 0; } + if (endptr) + *endptr = parse_ptr; + if (overflow) { errno = ERANGE; if (sign != Sign::Negative) { @@ -1003,6 +1006,9 @@ unsigned long long strtoull(const char* str, char** endptr, int base) return 0; } + if (endptr) + *endptr = parse_ptr; + if (overflow) { errno = ERANGE; return LONG_LONG_MAX;