fix #2601 (segmentation fault of cppcheck)

This commit is contained in:
Robert Reif 2011-02-22 07:02:15 -05:00
parent ba6c2ca310
commit 703448171a
2 changed files with 12 additions and 0 deletions

View File

@ -5980,6 +5980,9 @@ void Tokenizer::simplifyIfNotNull()
{
tok = tok->next();
if (!tok)
break;
if (Token::simpleMatch(tok, "0 != (") ||
Token::Match(tok, "0 != %var%"))
{

View File

@ -326,6 +326,8 @@ private:
TEST_CASE(simplifyFunctionReturn);
TEST_CASE(removeUnnecessaryQualification);
TEST_CASE(simplifyIfNotNull);
}
std::string tok(const char code[], bool simplify = true)
@ -6516,6 +6518,13 @@ private:
ASSERT_EQUALS(expected, tok(code, false));
ASSERT_EQUALS("[test.cpp:1]: (portability) Extra qualification 'Fred::' unnecessary and considered an error by many compilers.\n", errout.str());
}
void simplifyIfNotNull() // ticket # 2601 segmentation fault
{
const char code[] = "|| #if #define <=";
tok(code, false);
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestSimplifyTokens)