Update JSON parser to correctly handle 64-bit integers

This commit is contained in:
Mike Naquin
2012-12-13 09:39:50 -06:00
parent 27616fb0e6
commit d5858c15d4

View File

@@ -575,18 +575,20 @@ void Parser::readValue(const Token* token)
case Token::INTEGER_LITERAL_TOKEN: case Token::INTEGER_LITERAL_TOKEN:
if ( _handler != NULL ) if ( _handler != NULL )
{ {
int value = token->asInteger();
#if defined(POCO_HAVE_INT64) #if defined(POCO_HAVE_INT64)
if ( value == std::numeric_limits<int>::max() Int64 value = token->asInteger();
|| value == std::numeric_limits<int>::min() ) // if number is 32-bit, then handle as such
{ if ( value > std::numeric_limits<int>::max()
_handler->value(NumberParser::parse64(token->asString())); || value < std::numeric_limits<int>::min() )
} {
else _handler->value(value);
{ }
_handler->value(token->asInteger()); else
} {
_handler->value(static_cast<int>(value));
}
#else #else
int value = token->asInteger();
_handle->value(value); _handle->value(value);
#endif #endif
} }
@@ -697,5 +699,4 @@ bool Parser::readElements(bool firstCall)
throw JSONException(format("Invalid token '%s' found.", token->asString())); throw JSONException(format("Invalid token '%s' found.", token->asString()));
} }
} } // namespace Poco::JSON } } // namespace Poco::JSON