Fix crash on empty brackets

Relevant parts from the backtrace:
This commit is contained in:
Thomas Jarosch 2012-12-28 20:16:51 +01:00
parent 1769240e15
commit 1f87c6d669
2 changed files with 9 additions and 1 deletions

View File

@ -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();

View File

@ -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"