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))