Fixed #1944 (segfault in Tokenizer::simplifyLogicalOperator)

This commit is contained in:
Daniel Marjamäki 2010-08-17 20:06:20 +02:00
parent aa00587fed
commit 1fd773b245
2 changed files with 19 additions and 3 deletions

View File

@ -5314,9 +5314,9 @@ bool Tokenizer::simplifyLogicalOperators()
ret = true;
}
// "%var%|) and %var%|("
else if (Token::Match(tok, "and|or") &&
((Token::Match(tok->previous(), "%var%") || tok->previous()->str() == ")") ||
(Token::Match(tok->next(), "%var%") || tok->next()->str() == "(")))
else if (Token::Match(tok->previous(), "%any% and|or %any%") &&
((tok->previous()->isName() || tok->previous()->str() == ")") ||
(tok->next()->isName() || tok->next()->str() == "(")))
{
if (tok->str() == "and")
tok->str("&&");

View File

@ -109,6 +109,7 @@ private:
TEST_CASE(if_cond7);
TEST_CASE(if_cond8);
TEST_CASE(if_cond9);
TEST_CASE(if_cond10);
TEST_CASE(if_or);
@ -1050,6 +1051,21 @@ private:
ASSERT_EQUALS("\nabc\n\n", actual[""]);
}
void if_cond10()
{
const char filedata[] = "#if !defined(a) && !defined(b)\n"
"#if defined(and)\n"
"#endif\n"
"#endif\n";
// Preprocess => don't crash..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c");
}
void if_or()