Fixed #8349 (Noisy nullPointerRedundantCheck)

This commit is contained in:
Daniel Marjamäki 2019-07-27 20:02:49 +02:00
parent 0324bbf63c
commit e8ec6e6f11
2 changed files with 13 additions and 0 deletions

View File

@ -1795,6 +1795,12 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symbo
if (varid == 0U || !var) if (varid == 0U || !var)
continue; continue;
if (tok->str() == "?" && tok->isExpandedMacro()) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok, "variable " + var->name() + ", condition is defined in macro");
continue;
}
// bailout: for/while-condition, variable is changed in while loop // bailout: for/while-condition, variable is changed in while loop
for (const Token *tok2 = tok; tok2; tok2 = tok2->astParent()) { for (const Token *tok2 = tok; tok2; tok2 = tok2->astParent()) {
if (tok2->astParent() || tok2->str() != "(" || !Token::simpleMatch(tok2->link(), ") {")) if (tok2->astParent() || tok2->str() != "(" || !Token::simpleMatch(tok2->link(), ") {"))

View File

@ -1357,6 +1357,13 @@ private:
" M;\n" " M;\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:4]: (debug) valueflow.cpp:1260:valueFlowBeforeCondition bailout: variable x, condition is defined in macro\n", errout.str()); ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:4]: (debug) valueflow.cpp:1260:valueFlowBeforeCondition bailout: variable x, condition is defined in macro\n", errout.str());
bailout("#define FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)\n" // #8349
"void f(int *x) {\n"
" a = x;\n"
" FREE(x);\n"
"}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:4]: (debug) valueflow.cpp:1260:valueFlowBeforeCondition bailout: variable x, condition is defined in macro\n", errout.str());
} }
void valueFlowBeforeConditionGoto() { void valueFlowBeforeConditionGoto() {