Skip to content

Commit dfee044

Browse files
committed
value flow: Fixed wrong value in subfunction after conditional return
1 parent f79e1b6 commit dfee044

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
182182
{
183183
std::list<ValueFlow::Value> argvalues;
184184
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
185+
// passing value(s) to function
185186
if (Token::Match(tok, "[(,] %var% [,)]") && !tok->next()->values.empty())
186187
argvalues = tok->next()->values;
187188
else if (Token::Match(tok, "[(,] %num% [,)]")) {
@@ -226,7 +227,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
226227
} else if (tok2->varId() == varid2 || tok2->str() == "{") {
227228
if (settings->debugwarnings)
228229
bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str());
229-
continue;
230+
break;
230231
}
231232
}
232233
}

test/testvalueflow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ class TestValueFlow : public TestFixture {
136136
" if (x==0){}\n"
137137
"}";
138138
ASSERT_EQUALS(true, testValueOfX(code, 1U, 0));
139+
140+
code = "void f1(int x) {\n"
141+
" if (x == 0) return;\n"
142+
" int y = 1234 / x;\n"
143+
"}\n"
144+
"\n"
145+
"void f2() {\n"
146+
" f1(0);\n"
147+
"}";
148+
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
139149
}
140150
};
141151

0 commit comments

Comments
 (0)