Fixed #2897 (out of bounds false positive, using reinterpret_cast)

This commit is contained in:
Daniel Marjamäki 2011-07-21 09:32:24 +02:00
parent 05c22e0e36
commit 9f22d2fc6b
2 changed files with 11 additions and 0 deletions

View File

@ -5612,6 +5612,14 @@ void Tokenizer::simplifyCasts()
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
// #2897 : don't remove cast in such cases:
// *((char *)a + 1) = 0;
if (!tok->isName() && Token::simpleMatch(tok->next(), "* ("))
{
tok = tok->tokAt(2)->link();
continue;
}
while (Token::Match(tok->next(), "( %type% *| ) *|&| %var%") ||
Token::Match(tok->next(), "( %type% %type% *| ) *|&| %var%") ||
(!tok->isName() && (Token::Match(tok->next(), "( %type% * ) (") ||

View File

@ -434,6 +434,9 @@ private:
ASSERT_EQUALS("class A { A operator* ( int ) ; } ;", tok("class A { A operator *(int); };"));
ASSERT_EQUALS("class A { A operator* ( int ) const ; } ;", tok("class A { A operator *(int) const; };"));
ASSERT_EQUALS("if ( ! p )", tok("if (p == (char *)(char *)0)"));
// no simplification as the cast may be important here. see #2897 for example
ASSERT_EQUALS("; * ( ( char * ) p + 1 ) = 0 ;", tok("; *((char *)p + 1) = 0;"));
}