From ce9a3167fab1bb411c12cfc68cdaf26572fb6e20 Mon Sep 17 00:00:00 2001 From: Eduardo Arias Date: Mon, 21 Oct 2024 15:28:21 -0300 Subject: [PATCH] Use initialization list to initialize m_service - This is correct because base class is initialized before members are initialized. - Removes cppcheck suppression by addressing reported issue. - Leverage C++11's 'default member initializer' to initialize m_provider & m_demandsPassword and address Sonarcloud issue. --- src/operators/rbl.h | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/operators/rbl.h b/src/operators/rbl.h index 26fd483c..a36b0d9d 100644 --- a/src/operators/rbl.h +++ b/src/operators/rbl.h @@ -33,8 +33,8 @@ #include "src/operators/operator.h" -namespace modsecurity { -namespace operators { +namespace modsecurity::operators { + class Rbl : public Operator { public: @@ -66,21 +66,18 @@ class Rbl : public Operator { /** @ingroup ModSecurity_Operator */ explicit Rbl(std::unique_ptr param) - : m_service(), - m_demandsPassword(false), - m_provider(RblProvider::UnknownProvider), - Operator("Rbl", std::move(param)) { - m_service = m_string->evaluate(); // cppcheck-suppress useInitializationList + : Operator("Rbl", std::move(param)), + m_service(m_string->evaluate()) { if (m_service.find("httpbl.org") != std::string::npos) { m_demandsPassword = true; m_provider = RblProvider::httpbl; - } else if (m_service.find("uribl.com") != std::string::npos) { - m_provider = RblProvider::uribl; - } else if (m_service.find("spamhaus.org") != std::string::npos) { - m_provider = RblProvider::spamhaus; - } + } else if (m_service.find("uribl.com") != std::string::npos) { + m_provider = RblProvider::uribl; + } else if (m_service.find("spamhaus.org") != std::string::npos) { + m_provider = RblProvider::spamhaus; } + } bool evaluate(Transaction *transaction, RuleWithActions *rule, const std::string& input, RuleMessage &ruleMessage) override; @@ -98,12 +95,12 @@ class Rbl : public Operator { private: std::string m_service; - bool m_demandsPassword; - RblProvider m_provider; + bool m_demandsPassword = false; + RblProvider m_provider = RblProvider::UnknownProvider; }; -} // namespace operators -} // namespace modsecurity + +} // namespace modsecurity::operators #endif // SRC_OPERATORS_RBL_H_