Browse Source

Merge pull request #5489 from aaron-bray/master

Use NoLocalStrtod for international compliance
Adam Cozzette 6 years ago
parent
commit
43c3abf077

+ 2 - 0
cmake/libprotobuf-lite.cmake

@@ -7,6 +7,7 @@ set(libprotobuf_lite_files
   ${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.cc
   ${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.cc
   ${protobuf_source_dir}/src/google/protobuf/parse_context.cc
   ${protobuf_source_dir}/src/google/protobuf/parse_context.cc
   ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc
   ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc
+  ${protobuf_source_dir}/src/google/protobuf/io/strtod.cc
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
   ${protobuf_source_dir}/src/google/protobuf/message_lite.cc
   ${protobuf_source_dir}/src/google/protobuf/message_lite.cc
@@ -33,6 +34,7 @@ set(libprotobuf_lite_includes
   ${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.h
   ${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.h
   ${protobuf_source_dir}/src/google/protobuf/parse_context.h
   ${protobuf_source_dir}/src/google/protobuf/parse_context.h
   ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.h
   ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.h
+  ${protobuf_source_dir}/src/google/protobuf/io/strtod.h
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.h
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.h
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.h
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.h
   ${protobuf_source_dir}/src/google/protobuf/message_lite.h
   ${protobuf_source_dir}/src/google/protobuf/message_lite.h

+ 0 - 2
cmake/libprotobuf.cmake

@@ -16,7 +16,6 @@ set(libprotobuf_files
   ${protobuf_source_dir}/src/google/protobuf/generated_message_table_driven.cc
   ${protobuf_source_dir}/src/google/protobuf/generated_message_table_driven.cc
   ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.cc
   ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.cc
   ${protobuf_source_dir}/src/google/protobuf/io/printer.cc
   ${protobuf_source_dir}/src/google/protobuf/io/printer.cc
-  ${protobuf_source_dir}/src/google/protobuf/io/strtod.cc
   ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.cc
   ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.cc
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.cc
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.cc
   ${protobuf_source_dir}/src/google/protobuf/map_field.cc
   ${protobuf_source_dir}/src/google/protobuf/map_field.cc
@@ -72,7 +71,6 @@ set(libprotobuf_includes
   ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection.h
   ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection.h
   ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.h
   ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.h
   ${protobuf_source_dir}/src/google/protobuf/io/printer.h
   ${protobuf_source_dir}/src/google/protobuf/io/printer.h
-  ${protobuf_source_dir}/src/google/protobuf/io/strtod.h
   ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.h
   ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.h
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.h
   ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.h
   ${protobuf_source_dir}/src/google/protobuf/map_field.h
   ${protobuf_source_dir}/src/google/protobuf/map_field.h

+ 1 - 1
src/Makefile.am

@@ -213,6 +213,7 @@ libprotobuf_lite_la_SOURCES =                                  \
   google/protobuf/wire_format_lite.cc                          \
   google/protobuf/wire_format_lite.cc                          \
   google/protobuf/io/coded_stream.cc                           \
   google/protobuf/io/coded_stream.cc                           \
   google/protobuf/io/coded_stream_inl.h                        \
   google/protobuf/io/coded_stream_inl.h                        \
+  google/protobuf/io/strtod.cc                                 \
   google/protobuf/io/zero_copy_stream.cc                       \
   google/protobuf/io/zero_copy_stream.cc                       \
   google/protobuf/io/zero_copy_stream_impl_lite.cc
   google/protobuf/io/zero_copy_stream_impl_lite.cc
 
 
@@ -257,7 +258,6 @@ libprotobuf_la_SOURCES =                                       \
   google/protobuf/wrappers.pb.cc                               \
   google/protobuf/wrappers.pb.cc                               \
   google/protobuf/io/gzip_stream.cc                            \
   google/protobuf/io/gzip_stream.cc                            \
   google/protobuf/io/printer.cc                                \
   google/protobuf/io/printer.cc                                \
-  google/protobuf/io/strtod.cc                                 \
   google/protobuf/io/tokenizer.cc                              \
   google/protobuf/io/tokenizer.cc                              \
   google/protobuf/io/zero_copy_stream_impl.cc                  \
   google/protobuf/io/zero_copy_stream_impl.cc                  \
   google/protobuf/compiler/importer.cc                         \
   google/protobuf/compiler/importer.cc                         \

+ 4 - 3
src/google/protobuf/stubs/strutil.cc

@@ -42,6 +42,7 @@
 
 
 #include <google/protobuf/stubs/logging.h>
 #include <google/protobuf/stubs/logging.h>
 #include <google/protobuf/stubs/stl_util.h>
 #include <google/protobuf/stubs/stl_util.h>
+#include <google/protobuf/io/strtod.h>
 
 
 #ifdef _WIN32
 #ifdef _WIN32
 // MSVC has only _snprintf, not snprintf.
 // MSVC has only _snprintf, not snprintf.
@@ -1287,7 +1288,7 @@ char* DoubleToBuffer(double value, char* buffer) {
   // of a double.  This long double may have extra bits that make it compare
   // 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
   // unequal to "value" even though it would be exactly equal if it were
   // truncated to a double.
   // truncated to a double.
-  volatile double parsed_value = strtod(buffer, nullptr);
+  volatile double parsed_value = io::NoLocaleStrtod(buffer, nullptr);
   if (parsed_value != value) {
   if (parsed_value != value) {
     int snprintf_result =
     int snprintf_result =
       snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value);
       snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value);
@@ -1339,7 +1340,7 @@ bool safe_strtof(const char* str, float* value) {
   char* endptr;
   char* endptr;
   errno = 0;  // errno only gets set on errors
   errno = 0;  // errno only gets set on errors
 #if defined(_WIN32) || defined (__hpux)  // has no strtof()
 #if defined(_WIN32) || defined (__hpux)  // has no strtof()
-  *value = strtod(str, &endptr);
+  *value = io::NoLocaleStrtod(str, &endptr);
 #else
 #else
   *value = strtof(str, &endptr);
   *value = strtof(str, &endptr);
 #endif
 #endif
@@ -1348,7 +1349,7 @@ bool safe_strtof(const char* str, float* value) {
 
 
 bool safe_strtod(const char* str, double* value) {
 bool safe_strtod(const char* str, double* value) {
   char* endptr;
   char* endptr;
-  *value = strtod(str, &endptr);
+  *value = io::NoLocaleStrtod(str, &endptr);
   if (endptr != str) {
   if (endptr != str) {
     while (ascii_isspace(*endptr)) ++endptr;
     while (ascii_isspace(*endptr)) ++endptr;
   }
   }