From 8c9e0ff0f711616afa0c1a3252be587a3c0e53c7 Mon Sep 17 00:00:00 2001 From: Aaron Bray Date: Tue, 18 Dec 2018 21:55:22 -0500 Subject: [PATCH] Use NoLocalStrtod for international compliance Recieved errors pasing json files with decimal floats from European colleagues --- src/google/protobuf/stubs/strutil.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc index 5bf9f2e6a8..d45b3282ae 100644 --- a/src/google/protobuf/stubs/strutil.cc +++ b/src/google/protobuf/stubs/strutil.cc @@ -41,6 +41,7 @@ #include #include +#include #ifdef _WIN32 // MSVC has only _snprintf, not snprintf. @@ -1286,7 +1287,7 @@ char* DoubleToBuffer(double value, char* buffer) { // of a double. This long double may have extra bits that make it compare // unequal to "value" even though it would be exactly equal if it were // truncated to a double. - volatile double parsed_value = strtod(buffer, nullptr); + volatile double parsed_value = io::NoLocaleStrtod(buffer, nullptr); if (parsed_value != value) { int snprintf_result = snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value); @@ -1338,7 +1339,7 @@ bool safe_strtof(const char* str, float* value) { char* endptr; errno = 0; // errno only gets set on errors #if defined(_WIN32) || defined (__hpux) // has no strtof() - *value = strtod(str, &endptr); + *value = io::NoLocaleStrtod(str, &endptr); #else *value = strtof(str, &endptr); #endif @@ -1347,7 +1348,7 @@ bool safe_strtof(const char* str, float* value) { bool safe_strtod(const char* str, double* value) { char* endptr; - *value = strtod(str, &endptr); + *value = io::NoLocaleStrtod(str, &endptr); if (endptr != str) { while (ascii_isspace(*endptr)) ++endptr; }