Skip to content

Commit 6e52e27

Browse files
committed
Merge pull request open-source-parsers#294 from cdunn2001/master
fix ,/. problem in reader
2 parents bcb83b9 + 6416350 commit 6e52e27

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
@@ -597,33 +597,9 @@ bool Reader::decodeDouble(Token& token) {
597597

598598
bool Reader::decodeDouble(Token& token, Value& decoded) {
599599
double value = 0;
600-
const int bufferSize = 32;
601-
int count;
602-
int length = int(token.end_ - token.start_);
603-
604-
// Sanity check to avoid buffer overflow exploits.
605-
if (length < 0) {
606-
return addError("Unable to parse token length", token);
607-
}
608-
609-
// Avoid using a string constant for the format control string given to
610-
// sscanf, as this can cause hard to debug crashes on OS X. See here for more
611-
// info:
612-
//
613-
// http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html
614-
char format[] = "%lf";
615-
616-
if (length <= bufferSize) {
617-
Char buffer[bufferSize + 1];
618-
memcpy(buffer, token.start_, length);
619-
buffer[length] = 0;
620-
count = sscanf(buffer, format, &value);
621-
} else {
622-
std::string buffer(token.start_, token.end_);
623-
count = sscanf(buffer.c_str(), format, &value);
624-
}
625-
626-
if (count != 1)
600+
std::string buffer(token.start_, token.end_);
601+
std::istringstream is(buffer);
602+
if (!(is >> value))
627603
return addError("'" + std::string(token.start_, token.end_) +
628604
"' is not a number.",
629605
token);

0 commit comments

Comments
 (0)