From 01e5f14bf8ee7b0a7ee54922afc28bd7210f6e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 22 Nov 2016 23:59:39 +0100 Subject: [PATCH] CheckClass::virtualDestructorError and a variation of CheckNullPointer::nullPointerError would print inconclusive,warning messages altough no --enable=warning was given. Fix. --- lib/checkclass.cpp | 8 +++++--- lib/checknullpointer.cpp | 2 ++ test/testclass.cpp | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 203ee3370..1264eec75 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1647,14 +1647,16 @@ void CheckClass::virtualDestructor() void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived, bool inconclusive) { - if (inconclusive) - reportError(tok, Severity::warning, "virtualDestructor", "Class '" + Base + "' which has virtual members does not have a virtual destructor.", CWE404, true); - else + 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 { 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); + } } //--------------------------------------------------------------------------- diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 2c1eaca77..4fe2c9909 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -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 callstack; callstack.push_back(tok); callstack.push_back(nullCheck); diff --git a/test/testclass.cpp b/test/testclass.cpp index f130cf0f0..107a811de 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -1893,6 +1893,7 @@ private: errout.str(""); settings0.inconclusive = inconclusive; + settings0.addEnabled("warning"); // Tokenize.. Tokenizer tokenizer(&settings0, this);