diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index e36d47ff6..4ec068ac8 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -990,7 +990,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symbo Token::Match(tok, "%oror%|&& %name% %oror%|&&|)")) { vartok = tok->next(); num = 0; - } else if (tok->str() == "!" && tok->astOperand1() && tok->astOperand1()->isName()) { + } else if (Token::Match(tok, "[!?]") && Token::Match(tok->astOperand1(), "%name%")) { vartok = tok->astOperand1(); num = 0; } else { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index adec1c001..f396acf56 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -612,6 +612,12 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 123)); + code = "void f(const s *x) {\n" + " x->a = 0;\n" + " if (x ? x->a : 0) {}\n" + "}"; + ASSERT_EQUALS(true, testValueOfX(code, 2U, 0)); + code = "void f(int x, int y) {\n" " a = x;\n" " if (y){}\n"