Commit 98d0a2b1 by Geoff Lang Committed by Commit Bot

Use strtod instead of istringstream+locale for parsing floats.

BUG=803034 Change-Id: I69ca7a86e1841e86c6a8cf6a0b7279a8e42b0012 Reviewed-on: https://chromium-review.googlesource.com/937964 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 879f90d2
......@@ -48,23 +48,10 @@ bool numeric_lex_int(const std::string &str, IntType *value)
template <typename FloatType>
bool numeric_lex_float(const std::string &str, FloatType *value)
{
// On 64-bit Intel Android, istringstream is broken. Until this is fixed in
// a newer NDK, don't use it. Android doesn't have locale support, so this
// doesn't have to force the C locale.
// TODO(thakis): Remove this once this bug has been fixed in the NDK and
// that NDK has been rolled into chromium.
#if defined(ANGLE_PLATFORM_ANDROID) && __x86_64__
*value = strtod(str.c_str(), nullptr);
return errno != ERANGE;
#else
std::istringstream stream(str);
// Force "C" locale so that decimal character is always '.', and
// not dependent on the current locale.
stream.imbue(std::locale::classic());
stream >> (*value);
return !stream.fail() && std::isfinite(*value);
#endif
// Some platforms have issues with the usage of std::locale and std::stringstream and cause
// crashes. Usage of strtod appears to be safe.
*value = static_cast<FloatType>(strtod(str.c_str(), nullptr));
return errno != ERANGE && std::isfinite(*value);
}
} // namespace pp.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment