Skip to content

[NFC][libc] Clarifies underscores in n-char-sequence. #102193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions libc/src/__support/str_to_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -1160,13 +1160,11 @@ LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
index += 3;
StorageType nan_mantissa = 0;
// this handles the case of `NaN(n-character-sequence)`, where the
// n-character-sequence is made of 0 or more letters and numbers in any
// order.
// n-character-sequence is made of 0 or more letters, numbers, or
// underscore characters in any order.
if (src[index] == '(') {
size_t left_paren = index;
++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] == ')') {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/stdlib/strtof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ 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(underscores_are_ok)", 23, 0x7fc00000);
run_test(
"NaN(1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_)",
68, 0x7fc00000);
Expand Down
Loading