File tree Expand file tree Collapse file tree 1 file changed +3
-27
lines changed
Expand file tree Collapse file tree 1 file changed +3
-27
lines changed Original file line number Diff line number Diff line change @@ -1477,33 +1477,9 @@ bool OurReader::decodeDouble(Token& token) {
14771477
14781478bool OurReader::decodeDouble (Token& token, Value& decoded) {
14791479 double value = 0 ;
1480- const int bufferSize = 32 ;
1481- int count;
1482- int length = int (token.end_ - token.start_ );
1483-
1484- // Sanity check to avoid buffer overflow exploits.
1485- if (length < 0 ) {
1486- return addError (" Unable to parse token length" , token);
1487- }
1488-
1489- // Avoid using a string constant for the format control string given to
1490- // sscanf, as this can cause hard to debug crashes on OS X. See here for more
1491- // info:
1492- //
1493- // http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html
1494- char format[] = " %lf" ;
1495-
1496- if (length <= bufferSize) {
1497- Char buffer[bufferSize + 1 ];
1498- memcpy (buffer, token.start_ , length);
1499- buffer[length] = 0 ;
1500- count = sscanf (buffer, format, &value);
1501- } else {
1502- std::string buffer (token.start_ , token.end_ );
1503- count = sscanf (buffer.c_str (), format, &value);
1504- }
1505-
1506- if (count != 1 )
1480+ std::string buffer ( token.start_ , token.end_ );
1481+ std::istringstream is (buffer);
1482+ if (!(is >> value))
15071483 return addError (" '" + std::string (token.start_ , token.end_ ) +
15081484 " ' is not a number." ,
15091485 token);
You can’t perform that action at this time.
0 commit comments