Fixed #3705 (cppcheck crash (null pointer exception))

This commit is contained in:
Daniel Marjamäki 2012-04-09 15:06:06 +02:00
parent bbdeebafda
commit 6bae724cb6
2 changed files with 19 additions and 7 deletions

View File

@ -6987,9 +6987,10 @@ void Tokenizer::simplifyGoto()
break;
--lev;
}
if (!roundbraces && tok2->str() == "{") {
else if (!roundbraces && tok2->str() == "{") {
++lev;
} else if (!roundbraces && tok2->str() == "return") {
}
else if (!roundbraces && tok2->str() == "return") {
ret = true;
if (indentlevel == 1 && lev == 0)
ret2 = true;
@ -6998,7 +6999,7 @@ void Tokenizer::simplifyGoto()
token = token->next();
token->linenr(tok2->linenr());
token->varId(tok2->varId());
if (ret2 && tok2->str() == ";") {
if (ret2 && roundbraces == 0 && tok2->str() == ";") {
break;
}
if (token->str() == "(") {

View File

@ -161,10 +161,9 @@ private:
// Simplify goto..
TEST_CASE(goto1);
TEST_CASE(goto2);
// ticket #3138
TEST_CASE(goto3);
// ticket #3459
TEST_CASE(goto4);
TEST_CASE(goto3); // #3138
TEST_CASE(goto4); // #3459
TEST_CASE(goto5); // #3705 - return ({asm("");});
//remove dead code after flow control statements
TEST_CASE(flowControl);
@ -3225,6 +3224,18 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
void goto5() {
const char code[] = "int foo() {\n"
" goto err;\n"
"err:\n"
" return ( { __asm__(X); } ); "
"}\n";
ASSERT_EQUALS("int foo ( ) {"
" return { asm ( \"X\" ) ; } ;"
" return { asm ( \"X\" ) ; } ; "
"}", tok(code));
}
void flowControl() {
std::list<std::string> beforedead;
//beforedead.push_back("return");