Fixed #2897 (out of bounds false positive, using reinterpret_cast)
This commit is contained in:
parent
05c22e0e36
commit
9f22d2fc6b
|
@ -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% * ) (") ||
|
||||
|
|
|
@ -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;"));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue