Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! Truncate value of increment operator
Browse files Browse the repository at this point in the history
  • Loading branch information
francois-berder committed Apr 26, 2024
1 parent 0e04009 commit a951574
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit a951574

Please sign in to comment.