From e8ec6e6f11e3d3ed83c636b947079d8569f43d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 27 Jul 2019 20:02:49 +0200 Subject: [PATCH] Fixed #8349 (Noisy nullPointerRedundantCheck) --- lib/valueflow.cpp | 6 ++++++ test/testvalueflow.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index fbef0a626..97210e92e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1795,6 +1795,12 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symbo if (varid == 0U || !var) 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 for (const Token *tok2 = tok; tok2; tok2 = tok2->astParent()) { if (tok2->astParent() || tok2->str() != "(" || !Token::simpleMatch(tok2->link(), ") {")) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 10abd6a63..251f08c4a 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1357,6 +1357,13 @@ private: " 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()); + + 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() {