summaryrefslogtreecommitdiff
path: root/Libraries/LibC
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-28 02:21:38 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-28 02:26:49 +0200
commit08c05fbbd10b97bc008a90348fbaeae86cfcee50 (patch)
tree99c2f1075b2002be92888c635e62d8293c890cd8 /Libraries/LibC
parentb8d3dbcf2ddc5f357366dbd7cd3a82a7c3d292da (diff)
downloadserenity-08c05fbbd10b97bc008a90348fbaeae86cfcee50.zip
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..)
Diffstat (limited to 'Libraries/LibC')
-rw-r--r--Libraries/LibC/stdlib.cpp6
1 files 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 {