[libc-commits] [libc] ad84463 - [libc] Support underscores in NaN char sequences
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Aug 2 13:02:52 PDT 2023
Author: Michael Jones
Date: 2023-08-02T13:02:47-07:00
New Revision: ad844632b932f1805cd25a054ef953835152d605
URL: https://github.com/llvm/llvm-project/commit/ad844632b932f1805cd25a054ef953835152d605
DIFF: https://github.com/llvm/llvm-project/commit/ad844632b932f1805cd25a054ef953835152d605.diff
LOG: [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
Added:
Modified:
libc/src/__support/str_to_float.h
libc/test/src/stdlib/strtof_test.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h
index 2a8b93c7458a6e..813405ef2f0364 100644
--- a/libc/src/__support/str_to_float.h
+++ b/libc/src/__support/str_to_float.h
@@ -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;
diff --git a/libc/test/src/stdlib/strtof_test.cpp b/libc/test/src/stdlib/strtof_test.cpp
index 59bea795b93e00..9151cbeb88d587 100644
--- a/libc/test/src/stdlib/strtof_test.cpp
+++ b/libc/test/src/stdlib/strtof_test.cpp
@@ -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);
}
More information about the libc-commits
mailing list