Skip to content

Commit 30fa187

Browse files
committed
Fixed cppcheck-opensource#5549 (ValueFlow: Handle static variables better in valueFlowAfterAssign)
1 parent 568b967 commit 30fa187

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎lib/valueflow.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,12 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
490490
break;
491491
}
492492

493+
if (var->isStatic()) {
494+
if (settings->debugwarnings)
495+
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " bailout when conditional code that contains var is seen");
496+
break;
497+
}
498+
493499
// Remove conditional values
494500
std::list<ValueFlow::Value>::iterator it;
495501
for (it = values.begin(); it != values.end();) {

‎test/testvalueflow.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ class TestValueFlow : public TestFixture {
498498
"}";
499499
ASSERT_EQUALS(false, testValueOfX(code, 4U, 2));
500500

501+
code = "void f() {\n"
502+
" static int x = 0;\n"
503+
" if (x==0) x = getX();\n"
504+
" return x;\n"
505+
"}";
506+
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
507+
501508
// function
502509
code = "void f() {\n"
503510
" char *x = 0;\n"

0 commit comments

Comments
 (0)