From a95157417b2bfc2c1a96ddf51b87b5b2835f0464 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Fri, 26 Apr 2024 10:43:10 +0200 Subject: [PATCH] fixup! fixup! fixup! fixup! Truncate value of increment operator --- lib/valueflow.cpp | 6 +----- test/testvalueflow.cpp | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 140c6b77b738..ae1232539b97 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -606,11 +606,7 @@ static ValueFlow::Value truncateImplicitConversion(Token* parent, const ValueFlo static long long truncateIntValue(long long value, size_t value_size, const ValueType::Sign dst_sign) { - MathLib::biguint unsignedMaxValue; - if (value_size == 8) - unsignedMaxValue = 0x7FFFFFFFFFFFFFFFLLU; - else - unsignedMaxValue = (1ULL << (value_size * 8)) - 1ULL; + const MathLib::biguint unsignedMaxValue = (1ULL << (value_size * 8)) - 1ULL; const MathLib::biguint signBit = 1ULL << (value_size * 8 - 1); value &= unsignedMaxValue; if (dst_sign == ValueType::Sign::SIGNED && (value & signBit)) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index afa25b05b6b7..857ba3a01bc2 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7905,9 +7905,9 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(0LLU, values.back().intvalue); code = "int f() {\n" - " const int a[128] = {};\n" - " char b = -128;\n" - " return a[--b];\n" + " const int a[128] = {};\n" + " char b = -128;\n" + " return a[--b];\n" "}\n"; values = tokenValues(code, "--"); ASSERT_EQUALS(1U, values.size());