Skip to content

Commit 17181ac

Browse files
committed
Merge remote-tracking branch 'up/master' into 0.y.z
fix ,/. problem in open-source-parsers#294
2 parents 07623b7 + 6e52e27 commit 17181ac

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

src/lib_json/json_reader.cpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -557,33 +557,9 @@ bool Reader::decodeDouble(Token& token) {
557557

558558
bool Reader::decodeDouble(Token& token, Value& decoded) {
559559
double value = 0;
560-
const int bufferSize = 32;
561-
int count;
562-
int length = int(token.end_ - token.start_);
563-
564-
// Sanity check to avoid buffer overflow exploits.
565-
if (length < 0) {
566-
return addError("Unable to parse token length", token);
567-
}
568-
569-
// Avoid using a string constant for the format control string given to
570-
// sscanf, as this can cause hard to debug crashes on OS X. See here for more
571-
// info:
572-
//
573-
// http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html
574-
char format[] = "%lf";
575-
576-
if (length <= bufferSize) {
577-
Char buffer[bufferSize + 1];
578-
memcpy(buffer, token.start_, length);
579-
buffer[length] = 0;
580-
count = sscanf(buffer, format, &value);
581-
} else {
582-
std::string buffer(token.start_, token.end_);
583-
count = sscanf(buffer.c_str(), format, &value);
584-
}
585-
586-
if (count != 1)
560+
std::string buffer(token.start_, token.end_);
561+
std::istringstream is(buffer);
562+
if (!(is >> value))
587563
return addError("'" + std::string(token.start_, token.end_) +
588564
"' is not a number.",
589565
token);

0 commit comments

Comments
 (0)