#4245: Segmentation fault (invalid code); Applied patch from amai.

This commit is contained in:
Ettl Martin 2012-10-08 21:49:25 +02:00
parent f74c30e116
commit 0879bb5825
2 changed files with 9 additions and 1 deletions

View File

@ -5131,9 +5131,11 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar)
else if (strchr(";,", tok2->str()[0])) { else if (strchr(";,", tok2->str()[0])) {
// "type var =" => "type var; var =" // "type var =" => "type var; var ="
Token *VarTok = type0->tokAt((int)typelen); const Token *VarTok = type0->tokAt((int)typelen);
while (Token::Match(VarTok, "*|&|const")) while (Token::Match(VarTok, "*|&|const"))
VarTok = VarTok->next(); VarTok = VarTok->next();
if (!VarTok)
break; // ticket 4245 - invalid code probably
list.insertTokens(eq, VarTok, 2); list.insertTokens(eq, VarTok, 2);
eq->str(";"); eq->str(";");

View File

@ -58,6 +58,7 @@ private:
TEST_CASE(tokenize23); // tokenize "return - __LINE__;" TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
TEST_CASE(tokenize24); // #4195 (segmentation fault) TEST_CASE(tokenize24); // #4195 (segmentation fault)
TEST_CASE(tokenize25); // #4239 (segmentation fault) TEST_CASE(tokenize25); // #4239 (segmentation fault)
TEST_CASE(tokenize26); // #4245 (segmentation fault)
// don't freak out when the syntax is wrong // don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax1); TEST_CASE(wrong_syntax1);
@ -652,6 +653,11 @@ private:
tokenizeAndStringify("f ( struct { int typedef T x ; } ) { }"); tokenizeAndStringify("f ( struct { int typedef T x ; } ) { }");
} }
// #4245 - segfault
void tokenize26() {
tokenizeAndStringify("class x { protected : template < int y = } ;");
}
void wrong_syntax1() { void wrong_syntax1() {
{ {
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))"); const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");