From 08c05fbbd10b97bc008a90348fbaeae86cfcee50 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 28 Jul 2020 02:21:38 +0200 Subject: [PATCH] LibC: Fix strtol() not setting endptr correctly for "0" "0" was interpreted as a base-8 prefix, and the parse pointer was then unconditionally advanced, causing us to consume zero characters. This unbreaks the git port. :^) (We should really have tests for LibC..) --- Libraries/LibC/stdlib.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp index 542554d7b3..cd3b3385bb 100644 --- a/Libraries/LibC/stdlib.cpp +++ b/Libraries/LibC/stdlib.cpp @@ -873,8 +873,7 @@ long long strtoll(const char* str, char** endptr, int base) // Parse base if (base == 0) { if (*parse_ptr == '0') { - parse_ptr += 1; - if (*parse_ptr == 'x' || *parse_ptr == 'X') { + if (tolower(*(parse_ptr + 1)) == 'x') { base = 16; parse_ptr += 2; } else { @@ -950,8 +949,7 @@ unsigned long long strtoull(const char* str, char** endptr, int base) // Parse base if (base == 0) { if (*parse_ptr == '0') { - parse_ptr += 1; - if (*parse_ptr == 'x' || *parse_ptr == 'X') { + if (tolower(*(parse_ptr + 1)) == 'x') { base = 16; parse_ptr += 2; } else {