Fix part of #1262 (cppcheck false positives: 'Possible null pointer dereference'

http://sourceforge.net/apps/trac/cppcheck/ticket/1262
This commit is contained in:
Reijo Tomperi 2010-01-15 23:46:47 +02:00
parent f591d8f8e1
commit d37864f8c4
2 changed files with 10 additions and 1 deletions

View File

@ -3966,7 +3966,7 @@ bool Tokenizer::simplifyKnownVariables()
ret = true;
}
if (Token::Match(tok3->next(), "++|-- %varid%", varid) &&
if (Token::Match(tok3->next(), "++|-- %varid%", varid) && MathLib::isInt(value) &&
!Token::Match(tok3->tokAt(3), "[.[]"))
{
incdec(value, tok3->strAt(1));

View File

@ -89,6 +89,7 @@ private:
TEST_CASE(simplifyKnownVariables15);
TEST_CASE(simplifyKnownVariables16);
TEST_CASE(simplifyKnownVariables17);
TEST_CASE(simplifyKnownVariables18);
TEST_CASE(match1);
@ -957,6 +958,14 @@ private:
simplifyKnownVariables(code));
}
void simplifyKnownVariables18()
{
const char code[] = "void f ( ) { char *s = malloc(100);mp_ptr p = s; ++p; }";
ASSERT_EQUALS(
"void f ( ) { char * s ; s = malloc ( 100 ) ; mp_ptr p ; p = s ; ++ p ; }",
simplifyKnownVariables(code));
}
void match1()
{
// Match "%var% | %var%"