diff --git a/src/checkother.cpp b/src/checkother.cpp index 8ef7c59a7..2fc7ee54e 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -102,7 +102,7 @@ void CheckOther::WarningRedundantCode() } else if (Token::Match(tok2, "delete [ ] %var% ; }")) { - err = (strcmp(tok2->strAt(1), varname1) == 0); + err = (strcmp(tok2->strAt(3), varname1) == 0); } else if (Token::Match(tok2, "free ( %var% ) ; }")) { @@ -121,7 +121,7 @@ void CheckOther::WarningRedundantCode() } else if (Token::Match(tok2, "delete [ ] %var% ;")) { - err = (strcmp(tok2->strAt(1), varname1) == 0); + err = (strcmp(tok2->strAt(3), varname1) == 0); } else if (Token::Match(tok2, "free ( %var% ) ;")) { diff --git a/test/testother.cpp b/test/testother.cpp index 89986865b..5cc7adce4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -152,6 +152,13 @@ private: " delete p;\n" "}\n"); ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str()); + + check("void foo()\n" + "{\n" + " if (p)\n" + " delete [] p;\n" + "}\n"); + ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str()); } void unreachable1()