[libc-commits] [PATCH] D156927: [libc] Support underscores in NaN char sequences

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Aug 2 11:28:10 PDT 2023


michaelrj created this revision.
michaelrj added reviewers: lntue, sivachandra.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
michaelrj requested review of this revision.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156927

Files:
  libc/src/__support/str_to_float.h
  libc/test/src/stdlib/strtof_test.cpp


Index: libc/test/src/stdlib/strtof_test.cpp
===================================================================
--- libc/test/src/stdlib/strtof_test.cpp
+++ libc/test/src/stdlib/strtof_test.cpp
@@ -201,4 +201,8 @@
   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);
 }
Index: libc/src/__support/str_to_float.h
===================================================================
--- libc/src/__support/str_to_float.h
+++ libc/src/__support/str_to_float.h
@@ -1180,7 +1180,9 @@
       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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156927.546559.patch
Type: text/x-patch
Size: 1100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230802/2f39dd36/attachment.bin>


More information about the libc-commits mailing list