From 056850c44bde57772b52ee3092a45770ebf873ba Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 11 Dec 2018 12:48:46 -0500 Subject: [PATCH] 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. --- src/lib_json/json_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index cb88eab..ad7e15d 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1564,7 +1564,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) { // TODO: Help the compiler do the div and mod at compile time or get rid of // them. Value::LargestUInt maxIntegerValue = - isNegative ? Value::LargestUInt(-Value::minLargestInt) + isNegative ? Value::LargestUInt(Value::minLargestInt) : Value::maxLargestUInt; Value::LargestUInt threshold = maxIntegerValue / 10; Value::LargestUInt value = 0;