mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:07:45 +00:00
LibC: Fix strtol() not populating `endptr' for valid strings
We were not writing anything out to the `endptr` pointer if a number was successfully parsed from the input string. Fixes #460.
This commit is contained in:
parent
a20f3c6647
commit
266b9cb654
1 changed files with 5 additions and 2 deletions
|
@ -352,7 +352,8 @@ long strtol(const char* str, char** endptr, int base)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const char* estr = str + strlen(str) - 1;
|
size_t length = strlen(str);
|
||||||
|
const char* estr = str + length - 1;
|
||||||
long track = 1;
|
long track = 1;
|
||||||
long num = 0;
|
long num = 0;
|
||||||
while (estr >= str) {
|
while (estr >= str) {
|
||||||
|
@ -362,12 +363,14 @@ long strtol(const char* str, char** endptr, int base)
|
||||||
digit_value = 10 + (*estr - 'A');
|
digit_value = 10 + (*estr - 'A');
|
||||||
num += (track *= base) / base * digit_value;
|
num += (track *= base) / base * digit_value;
|
||||||
} else {
|
} else {
|
||||||
if (endptr != NULL)
|
if (endptr)
|
||||||
*endptr = const_cast<char*>(estr);
|
*endptr = const_cast<char*>(estr);
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
estr--;
|
estr--;
|
||||||
}
|
}
|
||||||
|
if (endptr)
|
||||||
|
*endptr = const_cast<char*>(str + length);
|
||||||
return num * sign;
|
return num * sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue