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..)
This commit is contained in:
Andreas Kling 2020-07-28 02:21:38 +02:00
parent b8d3dbcf2d
commit 08c05fbbd1

View file

@ -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 {