Skip to content

Commit ce9a316

Browse files
committed
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.
1 parent b0497d9 commit ce9a316

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/operators/rbl.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include "src/operators/operator.h"
3434

3535

36-
namespace modsecurity {
37-
namespace operators {
36+
namespace modsecurity::operators {
37+
3838

3939
class Rbl : public Operator {
4040
public:
@@ -66,21 +66,18 @@ class Rbl : public Operator {
6666

6767
/** @ingroup ModSecurity_Operator */
6868
explicit Rbl(std::unique_ptr<RunTimeString> param)
69-
: m_service(),
70-
m_demandsPassword(false),
71-
m_provider(RblProvider::UnknownProvider),
72-
Operator("Rbl", std::move(param)) {
73-
m_service = m_string->evaluate(); // cppcheck-suppress useInitializationList
69+
: Operator("Rbl", std::move(param)),
70+
m_service(m_string->evaluate()) {
7471
if (m_service.find("httpbl.org") != std::string::npos)
7572
{
7673
m_demandsPassword = true;
7774
m_provider = RblProvider::httpbl;
78-
} else if (m_service.find("uribl.com") != std::string::npos) {
79-
m_provider = RblProvider::uribl;
80-
} else if (m_service.find("spamhaus.org") != std::string::npos) {
81-
m_provider = RblProvider::spamhaus;
82-
}
75+
} else if (m_service.find("uribl.com") != std::string::npos) {
76+
m_provider = RblProvider::uribl;
77+
} else if (m_service.find("spamhaus.org") != std::string::npos) {
78+
m_provider = RblProvider::spamhaus;
8379
}
80+
}
8481
bool evaluate(Transaction *transaction, RuleWithActions *rule,
8582
const std::string& input,
8683
RuleMessage &ruleMessage) override;
@@ -98,12 +95,12 @@ class Rbl : public Operator {
9895

9996
private:
10097
std::string m_service;
101-
bool m_demandsPassword;
102-
RblProvider m_provider;
98+
bool m_demandsPassword = false;
99+
RblProvider m_provider = RblProvider::UnknownProvider;
103100
};
104101

105-
} // namespace operators
106-
} // namespace modsecurity
102+
103+
} // namespace modsecurity::operators
107104

108105

109106
#endif // SRC_OPERATORS_RBL_H_

0 commit comments

Comments
 (0)