Fixed #2621 (Segmentation fault for GCC statement expression)

This commit is contained in:
Daniel Marjamäki 2011-03-13 10:34:54 +01:00
parent 384729204f
commit f26bc6a75c
2 changed files with 13 additions and 1 deletions

View File

@ -635,7 +635,10 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
null = false; null = false;
// start token = first token after the if/while body // start token = first token after the if/while body
tok1 = tok1->previous()->link()->next(); tok1 = tok1->previous()->link();
tok1 = tok1 ? tok1->next() : NULL;
if (!tok1)
continue;
} }
// Name of the pointer // Name of the pointer

View File

@ -46,6 +46,7 @@ private:
TEST_CASE(nullpointer9); TEST_CASE(nullpointer9);
TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it
TEST_CASE(nullConstantDereference); // Dereference NULL constant TEST_CASE(nullConstantDereference); // Dereference NULL constant
TEST_CASE(gcc_statement_expression); // Don't crash
} }
void check(const char code[]) void check(const char code[])
@ -1003,6 +1004,14 @@ private:
} }
void gcc_statement_expression()
{
// Ticket #2621
check("void f(struct ABC *abc) {\n"
" ({ if (abc) dbg(); })\n"
"}");
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestNullPointer) REGISTER_TEST(TestNullPointer)