From 3300d39854a658fbca69b44f4f6067fb760f3248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 28 Apr 2014 06:21:48 +0200 Subject: [PATCH] Fixed #5721 (valueFlowBeforeCondition: stop when goto label is seen) --- lib/valueflow.cpp | 14 +++++++------- test/testvalueflow.cpp | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index e37ffbd4f..4d9467fc5 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -440,6 +440,13 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog if (tok2->str() == ")" && Token::Match(tok2->link()->previous(), "typeof|sizeof (")) tok2 = tok2->link(); + // goto label + if (Token::Match(tok2, "[;{}] %var% :")) { + if (settings->debugwarnings) + bailout(tokenlist, errorLogger, tok2->next(), "variable " + var->nameToken()->str() + " stopping on goto label"); + break; + } + if (tok2->str() == "}") { if (Token::findmatch(tok2->link(), "%varid%", tok2, varid)) { if (settings->debugwarnings) { @@ -487,13 +494,6 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog break; } } - - // goto label - if (Token::Match(tok2, "[;{}] %var% :")) { - if (settings->debugwarnings) - bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on goto label"); - break; - } } } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index dd56e7f95..2b4589317 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -455,7 +455,22 @@ private: "out:" " if (x==123){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on goto label\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (debug) ValueFlow bailout: variable x stopping on goto label\n", errout.str()); + + // #5721 - FP + bailout("static void f(int rc) {\n" + " ABC* abc = getabc();\n" + " if (!abc) { goto out };\n" + "\n" + " abc->majortype = 0;\n" + " if (FAILED(rc)) {}\n" + "\n" + "out:\n" + " if (abc) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: assignment of abc\n" + "[test.cpp:8]: (debug) ValueFlow bailout: variable abc stopping on goto label\n", + errout.str()); } void valueFlowAfterAssign() {