From 789b01aad2cbe2833ad052dade8c303669f60465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 24 Aug 2014 08:50:01 +0200 Subject: [PATCH] ValueFlow: fixed one more hang in valueFlowForward --- lib/valueflow.cpp | 10 +++------- test/testvalueflow.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index d7e0cec40..4f894de01 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -830,13 +830,9 @@ static bool valueFlowForward(Token * const startToken, errorLogger, tok2, "no simplification of " + tok2->str() + " within " + (Token::Match(parent,"[?:]") ? "?:" : parent->str()) + " expression"); - while (parent && parent->str() != "(") - parent = parent->astParent(); - if (parent) { - tok2 = const_cast(parent->link()); - if (Token::simpleMatch(tok2, ") (")) - tok2 = tok2->linkAt(1); - } + const Token *astTop = parent->astTop(); + if (Token::simpleMatch(astTop->astOperand1(), "for (")) + tok2 = const_cast(astTop->link()); continue; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 872f915ff..ca7c2f4fd 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1002,6 +1002,12 @@ private: "}"; testValueOfX(code, 0U, 0); + code = "void f() {\n" // don't hang in valueFlowForward analysis + " int x = 0;\n" + " f2((char*)a[b?c[x]:x]);\n" + "}"; + testValueOfX(code, 0U, 0); + // TODO: float code = "void f(float x) {\n" " if (x == 0.5) {}\n"