Fixed #4927 (Segfault in CheckOther::checkCommaSeparatedReturn() on invalid code)

This commit is contained in:
Alexander Mai 2013-07-28 10:39:58 +02:00 committed by Daniel Marjamäki
parent 43f0be06fa
commit 40fa474a5b
2 changed files with 10 additions and 1 deletions

View File

@ -1886,7 +1886,7 @@ void CheckOther::checkCommaSeparatedReturn()
for (const Token *tok = _tokenizer->tokens(); tok ; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok ; tok = tok->next()) {
if (Token::Match(tok ,"return")) { if (Token::Match(tok ,"return")) {
while (tok->str() != ";") { while (tok && tok->str() != ";") {
if (tok->str() == "(") if (tok->str() == "(")
tok=tok->link(); tok=tok->link();
@ -1911,6 +1911,9 @@ void CheckOther::checkCommaSeparatedReturn()
tok=tok->next(); tok=tok->next();
} }
// bailout: missing semicolon (invalid code / bad tokenizer)
if (!tok)
break;
} }
} }
} }

View File

@ -6310,6 +6310,12 @@ private:
" return a<int,\nint>::b;\n" " return a<int,\nint>::b;\n"
"}", NULL, false, false, false, false); "}", NULL, false, false, false, false);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// ticket #4927 Segfault in CheckOther::checkCommaSeparatedReturn() on invalid code
check("int main() {\n"
" return 0\n"
"}", NULL, false, false, false, false);
ASSERT_EQUALS("", errout.str());
} }
}; };