Fix JSON parsing of large unsigned 64-bit integers

This commit is contained in:
Mike Naquin
2013-02-21 12:57:51 -06:00
parent ae26e45bad
commit 13a1a0b9a2
7 changed files with 152 additions and 17 deletions

View File

@@ -636,20 +636,46 @@ void Parser::readValue(const Token* token)
if (_handler != NULL)
{
#if defined(POCO_HAVE_INT64)
Int64 value = token->asInteger64();
// if number is 32-bit, then handle as such
if (value > std::numeric_limits<int>::max()
|| value < std::numeric_limits<int>::min())
{
_handler->value(value);
}
else
{
_handler->value(static_cast<int>(value));
}
try
{
Int64 value = token->asInteger64();
// if number is 32-bit, then handle as such
if ( value > std::numeric_limits<int>::max()
|| value < std::numeric_limits<int>::min() )
{
_handler->value(value);
}
else
{
_handler->value(static_cast<int>(value));
}
}
// try to handle error as unsigned in case of overflow
catch ( const SyntaxException& )
{
UInt64 value = token->asUnsignedInteger64();
// if number is 32-bit, then handle as such
if ( value > std::numeric_limits<unsigned>::max() )
{
_handler->value(value);
}
else
{
_handler->value(static_cast<unsigned>(value));
}
}
#else
int value = token->asInteger();
_handle->value(value);
try
{
int value = token->asInteger();
_handle->value(value);
}
// try to handle error as unsigned in case of overflow
catch ( const SyntaxException& )
{
unsigned value = token->asUnsignedInteger();
_handle->value(value);
}
#endif
}
break;