-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Server Programmability
-
ALL
If the parseNumberFromStringHelper parse fails, we execute some fallback code on Win32 to handle the "nan" and "infinity" cases.
The way this is done, however, is incorrect.
There is only a match against the entire input string, not its prefix.
On match, the entire string is considered consumed according to the returned *endPtr, which is set to the end of the input string.
What should happen is that the beginning of the input should be matched against spaces,+/- signs and then any capitalization of INFINITY, INF, or NAN.
Nothing beyond those letters should be considered consumed.
Luckily the WSVC bug that this was all working around is no longer present.
The MSVC strtod behaves identically to the libc version nowadays.
So the workaround code is buggy but also unnecessary.
https://godbolt.org/z/zTab96W9s
#ifdef _WIN32 // The Windows libc implementation of strtod cannot parse +/-infinity or nan, // so handle that here. for (char& c : str) c = ctype::toLower(c); if (str == "nan"_sd) { *result = std::numeric_limits<double>::quiet_NaN(); if (endptr) *endptr = stringValue.data() + stringValue.size(); return Status::OK(); } else if (str == "+infinity"_sd || str == "infinity"_sd) { *result = std::numeric_limits<double>::infinity(); if (endptr) *endptr = stringValue.data() + stringValue.size(); return Status::OK(); } else if (str == "-infinity"_sd) { *result = -std::numeric_limits<double>::infinity(); if (endptr) *endptr = stringValue.data() + stringValue.size(); return Status::OK(); } #endif // defined(_WIN32)
- is related to
-
SERVER-96176 Avoid unnecessary string copies in NumberParser for double parsing
- Open