Skip to content

Commit 056850c

Browse files
bradkinghjmjohnson
authored andcommitted
reader: fix signed overflow when parsing negative value
Clang's ubsan (-fsanitize=undefined) reports: runtime error: negation of -9223372036854775808 cannot be represented in type 'Json::Value::LargestInt' (aka 'long'); cast to an unsigned type to negate this value to itself Follow its advice and update the code to remove the explicit negation.
1 parent 009a3ad commit 056850c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/lib_json/json_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
15641564
// TODO: Help the compiler do the div and mod at compile time or get rid of
15651565
// them.
15661566
Value::LargestUInt maxIntegerValue =
1567-
isNegative ? Value::LargestUInt(-Value::minLargestInt)
1567+
isNegative ? Value::LargestUInt(Value::minLargestInt)
15681568
: Value::maxLargestUInt;
15691569
Value::LargestUInt threshold = maxIntegerValue / 10;
15701570
Value::LargestUInt value = 0;

0 commit comments

Comments
 (0)