[libc] Support underscores in NaN char sequences

Other libc implementations support underscores in NaN(n-char-sequence)
strings. Us not supporting that is causing fuzz failures, so this patch
solves the problem.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D156927
This commit is contained in:
Michael Jones 2023-08-02 11:26:36 -07:00
parent 49d41de578
commit ad844632b9
2 changed files with 7 additions and 1 deletions

View File

@ -1180,7 +1180,9 @@ LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
if (src[index] == '(') {
size_t left_paren = index;
++index;
while (isalnum(src[index]))
// Apparently it's common for underscores to also be accepted. No idea
// why, but it's causing fuzz failures.
while (isalnum(src[index]) || src[index] == '_')
++index;
if (src[index] == ')') {
++index;

View File

@ -201,4 +201,8 @@ TEST_F(LlvmLibcStrToFTest, NaNWithParenthesesValidSequenceInvalidNumberTests) {
run_test("NaN(1a)", 7, 0x7fc00000);
run_test("NaN(asdf)", 9, 0x7fc00000);
run_test("NaN(1A1)", 8, 0x7fc00000);
run_test("NaN(why_does_this_work)", 23, 0x7fc00000);
run_test(
"NaN(1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_)",
68, 0x7fc00000);
}