fix #2682 (segmentation fault of cppcheck ( x a[0] = ))

This commit is contained in:
Robert Reif 2011-06-10 15:11:45 -04:00
parent ebd5a123ce
commit 3d4eb0d77e
2 changed files with 8 additions and 1 deletions

View File

@ -5877,7 +5877,7 @@ void Tokenizer::simplifyVarDecl()
tok2 = tok2->next(); tok2 = tok2->next();
if (tok2->str() == ";") if (tok2 && tok2->str() == ";")
tok2 = NULL; tok2 = NULL;
} }
} }

View File

@ -352,6 +352,7 @@ private:
TEST_CASE(removeUnnecessaryQualification2); TEST_CASE(removeUnnecessaryQualification2);
TEST_CASE(simplifyIfNotNull); TEST_CASE(simplifyIfNotNull);
TEST_CASE(simplifyVarDecl); // ticket # 2682 segmentation fault
} }
std::string tok(const char code[], bool simplify = true) std::string tok(const char code[], bool simplify = true)
@ -6983,7 +6984,13 @@ private:
"}"; "}";
ASSERT_EQUALS("void f ( int x ) { }", tok(code, false)); ASSERT_EQUALS("void f ( int x ) { }", tok(code, false));
} }
}
void simplifyVarDecl() // ticket # 2682 segmentation fault
{
const char code[] = "x a[0] =";
tok(code, false);
ASSERT_EQUALS("", errout.str());
} }
}; };