Fixed #2885 (crash of cppcheck while checking gcc-testsuite)

This commit is contained in:
Daniel Marjamäki 2011-07-21 16:13:35 +02:00
parent 31e3844f3f
commit fb3870071a
2 changed files with 25 additions and 13 deletions

View File

@ -5323,7 +5323,9 @@ void Tokenizer::simplifyConditionOperator()
} }
std::string str("if ( " + condition + " ) { " + var + " = " + value1 + " ; } else { " + var + " = " + value2 + " ; }"); Token *starttok = 0;
const std::string str("if ( condition ) { var = value1 ; } else { var = value2 ; }");
std::string::size_type pos1 = 0; std::string::size_type pos1 = 0;
while (pos1 != std::string::npos) while (pos1 != std::string::npos)
{ {
@ -5339,19 +5341,23 @@ void Tokenizer::simplifyConditionOperator()
pos1 = pos2 + 1; pos1 = pos2 + 1;
} }
tok = tok->next(); tok = tok->next();
}
if (isPointer) // set links.
{ if (tok->str() == "(" || tok->str() == "{")
Token::createMutualLinks(tok->tokAt(-17), tok->tokAt(-15)); starttok = tok;
Token::createMutualLinks(tok->tokAt(-14), tok->tokAt(-8)); else if (starttok && (tok->str() == ")" || tok->str() == "}"))
Token::createMutualLinks(tok->tokAt(-6), tok); {
} Token::createMutualLinks(starttok, tok);
else starttok = 0;
{ }
Token::createMutualLinks(tok->tokAt(-15), tok->tokAt(-13)); else if (tok->str() == "condition")
Token::createMutualLinks(tok->tokAt(-12), tok->tokAt(-7)); tok->str(condition);
Token::createMutualLinks(tok->tokAt(-5), tok); else if (tok->str() == "var")
tok->str(var);
else if (tok->str() == "value1")
tok->str(value1);
else if (tok->str() == "value2")
tok->str(value2);
} }
} }
} }

View File

@ -2739,6 +2739,12 @@ private:
"}\n"; "}\n";
ASSERT_EQUALS("int f ( int b , int * d ) { if ( b ) { b ++ ; } if ( b ) { * d = b ; } else { * d = 10 ; } return * d ; }", tok(code)); ASSERT_EQUALS("int f ( int b , int * d ) { if ( b ) { b ++ ; } if ( b ) { * d = b ; } else { * d = 10 ; } return * d ; }", tok(code));
} }
{
// Ticket #2885
const char code[] = "; s = x ? \" \" : \"-\" ;";
tok(code);
}
} }
void calculations() void calculations()