#1341·jsoncpp

OurReader::DecodeNumber leads to bad value type

Author: HartmutBoomCreated Oct 15, 2021Updated Sep 11, 2026
Labelsbug

We are using Jsoncpp 1.9.4 with Viual Studio 2015 in a Win32 configuration. We just have changed from Json::Reader to Json::CharReaderBuilder. When parsing the following text { "test":-1} to Json::Value val the expresstion val["test"].asInt() leads to a

cpp
JSON_ASSERT_MESSAGE(..., "LargestUInt out of Int range"),

as the type computed in OurReader::decodeNumber(Token& token, Value& decoded) is UInt.

Expected behavior I think a parsed value of -1 should lead to a Json::Value of type int. When I changed the followig code from

cpp
OurReader::decodeNumber(Token& token, Value& decoded)
....
if (isNegative)
{
	// We use the same magnitude assumption here, just in case.
	const auto last_digit = static_cast<Value::Int>(value % 10);// changed from Value:Uint to Value::Int
	decoded = -Value::LargestInt(value / 10) * 10 - last_digit;
}

... the problem is solved.

Desktop (please complete the following information):

  • OS: Windows 10

Additional context Visual Studio 2015 Win32 as target version

Source: open-source-parsers/jsoncpp