Fixed #4314: Using CheckNullPointer::isPointerDeRef() here is overkill and doesn't work as intended, since this function is designed to return 'false' if it isn't sure.

This commit is contained in:
PKEuS 2012-11-03 10:25:32 +01:00
parent c9e0089546
commit a36e008967
2 changed files with 6 additions and 3 deletions

View File

@ -19,7 +19,6 @@
//---------------------------------------------------------------------------
#include "checkother.h"
#include "checknullpointer.h" // CheckNullPointer::isPointerDeRef()
#include "mathlib.h"
#include "symboldatabase.h"
@ -3109,9 +3108,8 @@ void CheckOther::checkSuspiciousStringCompare()
const Variable* var = symbolDatabase->getVariableFromVarId(varTok->varId());
if (var) {
bool unknown=false;
if (_tokenizer->isC() ||
(var->isPointer() && !CheckNullPointer::isPointerDeRef(tok, unknown, symbolDatabase)))
(var->isPointer() && varTok->strAt(-1) != "*" && !Token::Match(varTok->next(), "[.([]")))
suspiciousStringCompareError(tok, var->name());
}
}

View File

@ -5181,6 +5181,11 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("bool foo(const Foo* c) {\n"
" return \"x\" == c->bar();\n" // #4314
"}");
ASSERT_EQUALS("", errout.str());
// Ticket #4257
check("bool foo() {\n"
"MyString *str=Getter();\n"