This is an archive of the discontinued LLVM Phabricator instance.

[libc] fix strtof/d/ld NaN parsing
ClosedPublic

Authored by michaelrj on Nov 12 2021, 12:05 PM.

Details

Summary

Fix the fact that previously strtof/d/ld would only accept a NaN as
having parentheses if the thing in the parentheses was a valid number,
now it will accept any combination of letters and numbers, but will only
put valid numbers in the mantissa.

Diff Detail

Event Timeline

michaelrj created this revision.Nov 12 2021, 12:05 PM
michaelrj requested review of this revision.Nov 12 2021, 12:05 PM
sivachandra accepted this revision.Nov 12 2021, 4:39 PM

There is a wide-spread violation of "no braces for single statement blocks."

libc/src/__support/str_to_float.h
790

Add a var named numberStart to avoid repeated parentStart + 1?

libc/test/src/stdlib/strtof_test.cpp
192

Add a comment explaining whats going on here and in the above line?

This revision is now accepted and ready to land.Nov 12 2021, 4:39 PM
michaelrj marked 2 inline comments as done.

clarify the code

libc/src/__support/str_to_float.h
790

While that is possible, I'm not sure if it would help. Currently parenStart + 1 is only used twice, so I don't think defining a new variable would be useful. Instead I renamed the variable to be leftParen, so that it's more clear that it points to the left parenthesis.

libc/test/src/stdlib/strtof_test.cpp
192

Should be more clear now.

This revision was automatically updated to reflect the committed changes.