Skip to content

Commit fd6eddb

Browse files
committed
use calculateArithmetic for ++/-- in ValueFlowAnalyzer::writeValue
1 parent 8c80299 commit fd6eddb

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
@@ -2457,6 +2457,14 @@ class TestValueFlow : public TestFixture {
24572457
"}\n";
24582458
ASSERT_EQUALS(true, testValueOfX(code, 3U, 1));
24592459

2460+
// increment past the maximum wraps without signed integer overflow
2461+
code = "void f() {\n"
2462+
" long long x = 0x7fffffffffffffff;\n"
2463+
" x++;\n"
2464+
" a = x;\n"
2465+
"}\n";
2466+
ASSERT_EQUALS(true, testValueOfX(code, 4U, LLONG_MIN));
2467+
24602468
code = "void f() {\n"
24612469
" int x = 123;\n"
24622470
" a = sizeof(x);\n"

0 commit comments

Comments
 (0)