Skip to content

Commit c36b636

Browse files
Make string to double conversion locale invariant.
1 parent 715bf72 commit c36b636

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/lib_json/json_reader.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <cassert>
1515
#include <cstring>
1616
#include <istream>
17+
#include <sstream>
1718

1819
#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below
1920
#define snprintf _snprintf
@@ -589,16 +590,22 @@ bool Reader::decodeDouble(Token& token, Value& decoded) {
589590
// info:
590591
//
591592
// http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html
592-
char format[] = "%lf";
593+
// char format[] = "%lf";
593594

594595
if (length <= bufferSize) {
595596
Char buffer[bufferSize + 1];
596597
memcpy(buffer, token.start_, length);
597598
buffer[length] = 0;
598-
count = sscanf(buffer, format, &value);
599+
std::istringstream is(buffer);
600+
is.imbue(std::locale::classic());
601+
is >> value;
602+
count = (is.good() || is.eof());
599603
} else {
600604
std::string buffer(token.start_, token.end_);
601-
count = sscanf(buffer.c_str(), format, &value);
605+
std::istringstream is(buffer);
606+
is.imbue(std::locale::classic());
607+
is >> value;
608+
count = (is.good() || is.eof());
602609
}
603610

604611
if (count != 1)

0 commit comments

Comments
 (0)