diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d330c73c0..cb44c6044 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2761,7 +2761,8 @@ void CheckOther::checkDoubleFree() // of previously freed variables. // TODO: There are false negatives. This bailout is only needed when the // loop will exit without free()'ing the memory on the last iteration. - else if (tok->str() == "}" && tok->link() && tok->link()->linkAt(-1) && + else if (tok->str() == "}" && tok->link() && tok->link()->tokAt(-1) && + tok->link()->linkAt(-1) && Token::Match(tok->link()->linkAt(-1)->previous(), "while|for") && Token::findmatch(tok->link()->linkAt(-1), "break|continue ;", tok) != NULL) { freedVariables.clear(); diff --git a/test/testother.cpp b/test/testother.cpp index ac6264ef5..2d6e76faf 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -35,6 +35,7 @@ private: void run() { TEST_CASE(oppositeInnerCondition); TEST_CASE(assignBoolToPointer); + TEST_CASE(emptyBrackets); TEST_CASE(zeroDiv1); TEST_CASE(zeroDiv2); @@ -311,6 +312,12 @@ private: ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout.str()); } + void emptyBrackets() { + check("{\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void zeroDiv1() { check("void foo()\n"