CheckClass::virtualDestructorError and a variation of CheckNullPointer::nullPointerError would print inconclusive,warning messages altough no --enable=warning was given. Fix.

This commit is contained in:
Matthias Krüger 2016-11-22 23:59:39 +01:00
parent 0b3751520b
commit 01e5f14bf8
3 changed files with 8 additions and 3 deletions

View File

@ -1647,15 +1647,17 @@ void CheckClass::virtualDestructor()
void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived, bool inconclusive)
{
if (inconclusive)
if (inconclusive) {
if (_settings->isEnabled("warning"))
reportError(tok, Severity::warning, "virtualDestructor", "Class '" + Base + "' which has virtual members does not have a virtual destructor.", CWE404, true);
else
} else {
reportError(tok, Severity::error, "virtualDestructor", "Class '" + Base + "' which is inherited by class '" + Derived + "' does not have a virtual destructor.\n"
"Class '" + Base + "' which is inherited by class '" + Derived + "' does not have a virtual destructor. "
"If you destroy instances of the derived class by deleting a pointer that points to the base class, only "
"the destructor of the base class is executed. Thus, dynamic memory that is managed by the derived class "
"could leak. This can be avoided by adding a virtual destructor to the base class.", CWE404, false);
}
}
//---------------------------------------------------------------------------
// warn for "this-x". The indented code may be "this->x"

View File

@ -487,6 +487,8 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var
void CheckNullPointer::nullPointerError(const Token *tok, const std::string &varname, const Token* nullCheck, bool inconclusive)
{
if (! _settings->isEnabled("warning"))
return;
std::list<const Token*> callstack;
callstack.push_back(tok);
callstack.push_back(nullCheck);

View File

@ -1893,6 +1893,7 @@ private:
errout.str("");
settings0.inconclusive = inconclusive;
settings0.addEnabled("warning");
// Tokenize..
Tokenizer tokenizer(&settings0, this);