Skip to content

Commit 14439b1

Browse files
committed
use calculateArithmetic for ++/-- in ValueFlowAnalyzer::writeValue
1 parent 9268253 commit 14439b1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎lib/vf_analyzers.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ struct ValueFlowAnalyzer : Analyzer {
371371
const std::string opName(inc ? "incremented" : "decremented");
372372
if (d == Direction::Reverse)
373373
inc = !inc;
374-
value->intvalue += (inc ? 1 : -1);
374+
value->intvalue = calculateArithmetic<MathLib::bigint>(inc ? '+' : '-', value->intvalue, 1);
375375

376376
/* Truncate value */
377377
const ValueType *dst = tok->valueType();

‎test/testvalueflow.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,6 +2471,14 @@ class TestValueFlow : public TestFixture {
24712471
"}\n";
24722472
ASSERT_EQUALS(true, testValueOfX(code, 3U, 1));
24732473

2474+
// increment past the maximum wraps without signed integer overflow
2475+
code = "void f() {\n"
2476+
" long long x = 0x7fffffffffffffff;\n"
2477+
" x++;\n"
2478+
" a = x;\n"
2479+
"}\n";
2480+
ASSERT_EQUALS(true, testValueOfX(code, 4U, LLONG_MIN));
2481+
24742482
code = "void f() {\n"
24752483
" int x = 123;\n"
24762484
" a = sizeof(x);\n"

0 commit comments

Comments
 (0)