Fixed #1197 (Segmentation fault when we define function which was already defined by preprocessor)

http://sourceforge.net/apps/trac/cppcheck/ticket/1197
This commit is contained in:
Slava Semushin 2010-01-02 03:25:37 +06:00
parent ddfd0b948e
commit b816968f28
2 changed files with 22 additions and 11 deletions

View File

@ -5147,17 +5147,6 @@ void Tokenizer::simplifyWhile0()
if (!Token::simpleMatch(tok, "while ( 0 )"))
continue;
// remove "while (0) { .. }"
if (Token::simpleMatch(tok->tokAt(4), "{"))
{
const Token *end = tok->tokAt(4)->link();
if (!findmatch(tok, end, "continue|break"))
{
Token::eraseTokens(tok, end ? end->next() : 0);
tok->deleteThis(); // delete "while"
}
}
if (Token::simpleMatch(tok->previous(), "}"))
{
// find "do"
@ -5180,5 +5169,17 @@ void Tokenizer::simplifyWhile0()
continue;
}
}
// remove "while (0) { .. }"
if (Token::simpleMatch(tok->tokAt(4), "{"))
{
const Token *end = tok->tokAt(4)->link();
if (!findmatch(tok, end, "continue|break"))
{
Token::eraseTokens(tok, end ? end->next() : 0);
tok->deleteThis(); // delete "while"
}
}
}
}

View File

@ -153,6 +153,7 @@ private:
// simplify "while (0)"
TEST_CASE(while0);
TEST_CASE(while1);
}
std::string tok(const char code[], bool simplify = true)
@ -2551,6 +2552,15 @@ private:
ASSERT_EQUALS("; do { continue ; } while ( false ) ;", tok("; do { continue ; } while (0);"));
ASSERT_EQUALS("; do { break ; } while ( false ) ;", tok("; do { break; } while (0);"));
}
void while1()
{
// ticket #1197
const char code[] = "void do {} while (0) { }";
const char expected[] = "void { }";
ASSERT_EQUALS(expected, tok(code));
}
};
REGISTER_TEST(TestSimplifyTokens)