Fixed #1271 (SIGSEGV on malformed source (macro stub + fundef))

This commit is contained in:
Daniel Marjamäki 2010-01-16 13:56:57 +01:00
parent a0caea4ee6
commit 0a8ca1f160
2 changed files with 12 additions and 8 deletions

View File

@ -555,6 +555,11 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
return; return;
} }
{
TIMER_START();
_tokenizer.fillFunctionList();
TIMER_END("Tokenizer::fillFunctionList");
}
if (_settings.isEnabled("unusedFunctions") && _settings._jobs == 1) if (_settings.isEnabled("unusedFunctions") && _settings._jobs == 1)
_checkUnusedFunctions.parseTokens(_tokenizer); _checkUnusedFunctions.parseTokens(_tokenizer);

View File

@ -2213,6 +2213,9 @@ void Tokenizer::simplifySizeof()
bool Tokenizer::simplifyTokenList() bool Tokenizer::simplifyTokenList()
{ {
// clear the _functionList so it can't contain dead pointers
_functionList.clear();
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (Token::simpleMatch(tok, "* const")) if (Token::simpleMatch(tok, "* const"))
@ -4655,17 +4658,13 @@ void Tokenizer::fillFunctionList()
{ {
_functionList.clear(); _functionList.clear();
int indentlevel = 0;
for (const Token *tok = _tokens; tok; tok = tok->next()) for (const Token *tok = _tokens; tok; tok = tok->next())
{ {
if (tok->str() == "{") if (tok->str() == "{")
++indentlevel;
else if (tok->str() == "}")
--indentlevel;
if (indentlevel > 0)
{ {
tok = tok->link();
if (!tok)
break;
continue; continue;
} }
@ -4695,7 +4694,7 @@ void Tokenizer::fillFunctionList()
else else
{ {
tok = tok2; tok = tok2;
while (tok->next() && !strchr(";{", tok->strAt(1)[0])) while (tok->next() && !Token::Match(tok->next(), "[;{]"))
tok = tok->next(); tok = tok->next();
} }
break; break;