Fix part of #1262 (cppcheck false positives: 'Possible null pointer dereference'
http://sourceforge.net/apps/trac/cppcheck/ticket/1262
This commit is contained in:
parent
f591d8f8e1
commit
d37864f8c4
|
@ -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));
|
||||
|
|
|
@ -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%"
|
||||
|
|
Loading…
Reference in New Issue