From 7fb812f41590112280b344e934fdb727579e3d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 16 Oct 2016 07:15:28 +0200 Subject: [PATCH] Fixed #7752 (ValueFlow: no conditional value, probably because condition is in ternary operator and/or in function call.) --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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"