From 66f3e86e65b27131797ef3d7ec68d208e826e01b 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 5c593973b854..b7eb523cc195 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))