From f58e1ab80eefb2a07c50d4fe9b44439d2dbab48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 11 Jan 2014 21:21:00 +0100 Subject: [PATCH] value flow: fixed fp in switch --- lib/valueflow.cpp | 4 ++++ test/testvalueflow.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ed85f5d3f..13f090230 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -245,6 +245,10 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog if (Token::Match(tok2->previous(), ") {") && !Token::Match(tok2->linkAt(-1)->previous(), "if|for|while (")) break; + } else if (tok2->str() == "break") { + if (settings->debugwarnings) + bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on break"); + break; } } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 0eaab11f8..5f34df0f5 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -210,6 +210,15 @@ private: " if (x == 123) {}\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (debug) ValueFlow bailout: global variable x\n", errout.str()); + + // bailout: switch + bailout("void f(int x, int y) {\n" + " switch (y) {\n" + " case 1: a=x; break;\n" + " case 2: if (x==5) {} break;\n" + " };\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on break\n", errout.str()); } void valueFlowForLoop() {