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

View File

@ -161,10 +161,9 @@ private:
// Simplify goto.. // Simplify goto..
TEST_CASE(goto1); TEST_CASE(goto1);
TEST_CASE(goto2); TEST_CASE(goto2);
// ticket #3138 TEST_CASE(goto3); // #3138
TEST_CASE(goto3); TEST_CASE(goto4); // #3459
// ticket #3459 TEST_CASE(goto5); // #3705 - return ({asm("");});
TEST_CASE(goto4);
//remove dead code after flow control statements //remove dead code after flow control statements
TEST_CASE(flowControl); TEST_CASE(flowControl);
@ -3225,6 +3224,18 @@ private:
ASSERT_EQUALS(expected, tok(code)); 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() { void flowControl() {
std::list<std::string> beforedead; std::list<std::string> beforedead;
//beforedead.push_back("return"); //beforedead.push_back("return");