Fixed #2386 (segmentation fault occurs in the checking when typedef has same name as an enum constant)

This commit is contained in:
Daniel Marjamäki 2010-12-31 20:55:28 +01:00
parent 3e5614a5a3
commit 2da3fea1b8
3 changed files with 20 additions and 1 deletions

View File

@ -341,6 +341,11 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
while (tok && tok->str() != "{" && tok->str() != ";")
tok = tok->next();
tok = tok ? tok->link() : 0;
if (!tok)
{
ExecutionPath::bailOut(checks);
return;
}
}
if (Token::Match(tok, "= {"))

View File

@ -8415,8 +8415,10 @@ void Tokenizer::simplifyStructDecl()
Token *type = tok->next();
Token *next = tok->tokAt(2);
while (next->str() != "{")
while (next && next->str() != "{")
next = next->next();
if (!next)
continue;
tok = next->link();
restart = next;

View File

@ -195,6 +195,7 @@ private:
TEST_CASE(executionPaths1);
TEST_CASE(executionPaths2);
TEST_CASE(executionPaths3); // no FP for function parameter
TEST_CASE(executionPaths4); // Ticket #2386 - Segmentation fault in the ExecutionPath handling
TEST_CASE(cmdLineArgs1);
@ -2685,6 +2686,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void executionPaths4()
{
// Ticket #2386 - Segmentation fault upon strange syntax
epcheck("void f() {\n"
" switch ( x ) {\n"
" case struct Tree : break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void cmdLineArgs1()
{
check("int main(int argc, char* argv[])\n"