Skip to content

Commit 1cbd25f

Browse files
authored
[NFC][libc] Clarifies underscores in n-char-sequence. (#102193)
The C standard specifies n-char-sequence: digit nondigit n-char-sequence digit n-char-sequence nondigit nondigit is specified as one of: _ a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z This means nondigit includes the underscore character. This patch clarifies this status in the comments and the test. Note C17 specifies n-char-sequence for NaN() as optional, and an empty sequence is not a valid n-char-sequence. However the current comment has the same effect as using the pedantic wording. So I left that part unchanged.
1 parent a0c57a0 commit 1cbd25f

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

libc/src/__support/str_to_float.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,13 +1159,11 @@ LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
11591159
index += 3;
11601160
StorageType nan_mantissa = 0;
11611161
// this handles the case of `NaN(n-character-sequence)`, where the
1162-
// n-character-sequence is made of 0 or more letters and numbers in any
1163-
// order.
1162+
// n-character-sequence is made of 0 or more letters, numbers, or
1163+
// underscore characters in any order.
11641164
if (src[index] == '(') {
11651165
size_t left_paren = index;
11661166
++index;
1167-
// Apparently it's common for underscores to also be accepted. No idea
1168-
// why, but it's causing fuzz failures.
11691167
while (isalnum(src[index]) || src[index] == '_')
11701168
++index;
11711169
if (src[index] == ')') {

libc/test/src/stdlib/strtof_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ TEST_F(LlvmLibcStrToFTest, NaNWithParenthesesValidSequenceInvalidNumberTests) {
200200
run_test("NaN(1a)", 7, 0x7fc00000);
201201
run_test("NaN(asdf)", 9, 0x7fc00000);
202202
run_test("NaN(1A1)", 8, 0x7fc00000);
203-
run_test("NaN(why_does_this_work)", 23, 0x7fc00000);
203+
run_test("NaN(underscores_are_ok)", 23, 0x7fc00000);
204204
run_test(
205205
"NaN(1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_)",
206206
68, 0x7fc00000);

0 commit comments

Comments
 (0)