From 4818ba9c9e444f079603dd38b0b16029de056321 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Tue, 30 Apr 2024 23:06:57 +0200 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Truncate value of increment operator --- lib/valueflow.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 7e7cf5b9a813..b482005a943a 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -606,7 +606,10 @@ static ValueFlow::Value truncateImplicitConversion(Token* parent, const ValueFlo static long long truncateIntValue(long long value, size_t value_size, const ValueType::Sign dst_sign) { - const MathLib::biguint unsignedMaxValue = std::numeric_limits::max() >> (sizeof(unsignedMaxValue) != value_size ? ((sizeof(unsignedMaxValue) - value_size) * 8) : 0); + if (value_size == 0) + return value; + + const MathLib::biguint unsignedMaxValue = std::numeric_limits::max() >> (value_size < sizeof(unsignedMaxValue) ? ((sizeof(unsignedMaxValue) - value_size) * 8) : 0); const MathLib::biguint signBit = 1ULL << (value_size * 8 - 1); value &= unsignedMaxValue; if (dst_sign == ValueType::Sign::SIGNED && (value & signBit))