Fixed #1086 (segmentation fault of cppcheck '#if define(A)+define(B)+define(C)!=1')

This commit is contained in:
Daniel Marjamäki 2009-12-15 20:18:32 +01:00
parent e03ff727d4
commit 1680d1fb42
2 changed files with 25 additions and 5 deletions

View File

@ -3848,10 +3848,10 @@ bool Tokenizer::simplifyCalculations()
} }
// (1-2) // (1-2)
if (Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% [],);=<>+-*/]") || while (Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% [],);=<>+-*/]") ||
Token::Match(tok, "<< %num% [+-*/] %num% [],);=<>+-*/]") || Token::Match(tok, "<< %num% [+-*/] %num% [],);=<>+-*/]") ||
Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% <<") || Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% <<") ||
Token::Match(tok, "<< %num% [+-*/] %num% <<")) Token::Match(tok, "<< %num% [+-*/] %num% <<"))
{ {
tok = tok->next(); tok = tok->next();
@ -3877,7 +3877,7 @@ bool Tokenizer::simplifyCalculations()
// instead of ((2 + 2) - (2 - 2)) = 4 // instead of ((2 + 2) - (2 - 2)) = 4
if (Token::Match(tok->next(), "[+-*/]")) if (Token::Match(tok->next(), "[+-*/]"))
{ {
tok = tok->tokAt(-2); tok = tok->previous();
continue; continue;
} }

View File

@ -100,6 +100,7 @@ private:
TEST_CASE(if_cond5); TEST_CASE(if_cond5);
TEST_CASE(if_cond6); TEST_CASE(if_cond6);
TEST_CASE(if_cond7); TEST_CASE(if_cond7);
TEST_CASE(if_cond8);
TEST_CASE(if_or); TEST_CASE(if_or);
@ -836,6 +837,25 @@ private:
} }
void if_cond8()
{
const char filedata[] = "#if defined(A) + defined(B) + defined(C) != 1\n"
"#endif\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(1, actual.size());
ASSERT_EQUALS("\n\n", actual[""]);
}
void if_or() void if_or()
{ {
const char filedata[] = "#if defined(DEF_10) || defined(DEF_11)\n" const char filedata[] = "#if defined(DEF_10) || defined(DEF_11)\n"