Fix #8266 identicalConditionAfterEarlyExit variable modified in if-clause (#3610)

This commit is contained in:
chrchr-github 2021-12-18 22:52:54 +01:00 committed by GitHub
parent 0c3531ea61
commit 8df25ec4e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 16 deletions

View File

@ -660,22 +660,8 @@ void CheckCondition::multiCondition2()
const Token * condStartToken = tok->str() == "if" ? tok->next() : tok;
const Token * condEndToken = tok->str() == "if" ? condStartToken->link() : Token::findsimplematch(condStartToken, ";");
// Does condition modify tracked variables?
if (const Token *op = Token::findmatch(tok, "++|--", condEndToken)) {
bool bailout = false;
while (op) {
if (vars.find(op->astOperand1()->varId()) != vars.end()) {
bailout = true;
if (isExpressionChanged(cond1, condStartToken, condEndToken, mSettings, mTokenizer->isCPP()))
break;
}
if (nonlocal && op->astOperand1()->varId() == 0) {
bailout = true;
break;
}
op = Token::findmatch(op->next(), "++|--", condEndToken);
}
if (bailout)
break;
}
// Condition..
const Token *cond2 = tok->str() == "if" ? condStartToken->astOperand2() : condStartToken->astOperand1();

View File

@ -3810,6 +3810,24 @@ private:
" uint8_t d0 = message->length > 0 ? data[0] : 0xff;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #8266
check("void f(bool b) {\n"
" if (b)\n"
" return;\n"
" if (g(&b) || b)\n"
" return;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #9720
check("bool bar(int &);\n"
"void f(int a, int b) {\n"
" if (a + b == 3)\n"
" return;\n"
" if (bar(a) && (a + b == 3)) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueSymbolic()