Fix crash on empty brackets
Relevant parts from the backtrace:
This commit is contained in:
parent
1769240e15
commit
1f87c6d669
|
@ -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();
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue