Skip to content

Commit

Permalink
Added const reported by cppcheck 2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
eduar-hte committed Apr 29, 2024
1 parent 13bfd91 commit c6fbeca
Show file tree
Hide file tree
Showing 28 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AnchoredSetVariableTranslationProxy {
: m_name(name),
m_fount(fount)
{
m_translate = [](std::string *name, std::vector<const VariableValue *> *l) {
m_translate = [](const std::string *name, std::vector<const VariableValue *> *l) {
for (int i = 0; i < l->size(); ++i) {
VariableValue *newVariableValue = new VariableValue(name, &l->at(i)->getKey(), &l->at(i)->getKey());
const VariableValue *oldVariableValue = l->at(i);
Expand Down
12 changes: 6 additions & 6 deletions headers/modsecurity/rule_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RuleMessage {
* unnecessary data duplication. Needs to be shrink down.
*
*/
RuleMessage(RuleWithActions *rule, Transaction *trans) :
RuleMessage(RuleWithActions *rule, const Transaction *trans) :
m_accuracy(rule->m_accuracy),
m_clientIpAddress(trans->m_clientIpAddress),
m_data(""),
Expand All @@ -73,7 +73,7 @@ class RuleMessage {
m_tags()
{ }

explicit RuleMessage(RuleMessage *rule) :
explicit RuleMessage(const RuleMessage *rule) :
m_accuracy(rule->m_accuracy),
m_clientIpAddress(rule->m_clientIpAddress),
m_data(rule->m_data),
Expand Down Expand Up @@ -158,16 +158,16 @@ class RuleMessage {
m_ver = "";
}

std::string log() {
std::string log() const {
return log(this, 0);
}
std::string log(int props) {
std::string log(int props) const {
return log(this, props);
}
std::string log(int props, int responseCode) {
std::string log(int props, int responseCode) const {
return log(this, props, responseCode);
}
std::string errorLog() {
std::string errorLog() const {
return log(this,
ClientLogMessageInfo | ErrorLogTailLogMessageInfo);
}
Expand Down
4 changes: 2 additions & 2 deletions headers/modsecurity/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Rules {
int append(Rules *from, const std::vector<int64_t> &ids, std::ostringstream *err) {
size_t j = 0;
for (; j < from->size(); j++) {
RuleWithOperator *rule = dynamic_cast<RuleWithOperator *>(from->at(j).get());
const RuleWithOperator *rule = dynamic_cast<RuleWithOperator *>(from->at(j).get());
if (rule && std::binary_search(ids.begin(), ids.end(), rule->m_ruleId)) {
if (err != NULL) {
*err << "Rule id: " << std::to_string(rule->m_ruleId) \
Expand All @@ -68,7 +68,7 @@ class Rules {
}

bool insert(std::shared_ptr<Rule> rule, const std::vector<int64_t> *ids, std::ostringstream *err) {
RuleWithOperator *r = dynamic_cast<RuleWithOperator *>(rule.get());
const RuleWithOperator *r = dynamic_cast<RuleWithOperator *>(rule.get());
if (r && ids != nullptr && std::binary_search(ids->begin(), ids->end(), r->m_ruleId)) {
if (err != nullptr) {
*err << "Rule id: " << std::to_string(r->m_ruleId) \
Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/rules_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extern "C" {
#endif

RulesSet *msc_create_rules_set(void);
void msc_rules_dump(RulesSet *rules);
void msc_rules_dump(const RulesSet *rules);
int msc_rules_merge(RulesSet *rules_dst, RulesSet *rules_from, const char **error);
int msc_rules_add_remote(RulesSet *rules, const char *key, const char *uri,
const char **error);
Expand Down
8 changes: 4 additions & 4 deletions headers/modsecurity/rules_set_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ConfigInt {
bool m_set;
int m_value;

void merge(ConfigInt *from) {
void merge(const ConfigInt *from) {
if (m_set == true || from->m_set == false) {
return;
}
Expand All @@ -87,7 +87,7 @@ class ConfigDouble {
bool m_set;
double m_value;

void merge(ConfigDouble *from) {
void merge(const ConfigDouble *from) {
if (m_set == true || from->m_set == false) {
return;
}
Expand All @@ -104,7 +104,7 @@ class ConfigString {
bool m_set;
std::string m_value;

void merge(ConfigString *from) {
void merge(const ConfigString *from) {
if (m_set == true || from->m_set == false) {
return;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ class ConfigUnicodeMap {
static void loadConfig(std::string f, double codePage,
RulesSetProperties *driver, std::string *errg);

void merge(ConfigUnicodeMap *from) {
void merge(const ConfigUnicodeMap *from) {
if (from->m_set == false) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ int msc_process_uri(Transaction *transaction, const char *uri,
const char *protocol, const char *http_version);

/** @ingroup ModSecurity_C_API */
const char *msc_get_response_body(Transaction *transaction);
const char *msc_get_response_body(const Transaction *transaction);

/** @ingroup ModSecurity_C_API */
size_t msc_get_response_body_length(Transaction *transaction);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int Lua::blob_keeper(lua_State *L, const void *p, size_t sz, void *ud) {


const char *Lua::blob_reader(lua_State *L, void *ud, size_t *size) {
LuaScriptBlob *lsb = static_cast<LuaScriptBlob *>(ud);
const LuaScriptBlob *lsb = static_cast<LuaScriptBlob *>(ud);
const char *data = lsb->read(size);
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/operators/pm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool Pm::init(const std::string &file, std::string *error) {
std::istream_iterator<std::string>(),
back_inserter(vec));

for (auto &a : vec) {
for (const auto &a : vec) {
acmp_add_pattern(m_p, a.c_str(), NULL, NULL, a.length());
}

Expand Down
2 changes: 1 addition & 1 deletion src/operators/verify_cpf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int VerifyCPF::convert_to_int(const char c) {
}


bool VerifyCPF::verify(const char *cpfnumber, int len) {
bool VerifyCPF::verify(const char *cpfnumber, int len) const {
int factor, part_1, part_2, var_len = len;
unsigned int sum = 0, i = 0, cpf_len = 11, c;
int cpf[11];
Expand Down
2 changes: 1 addition & 1 deletion src/operators/verify_cpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class VerifyCPF : public Operator {
const std::string& input,
std::shared_ptr<RuleMessage> ruleMessage) override;

bool verify(const char *ssnumber, int len);
bool verify(const char *ssnumber, int len) const;

private:
static int convert_to_int(const char c);
Expand Down
2 changes: 1 addition & 1 deletion src/operators/verify_svnr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int VerifySVNR::convert_to_int(const char c) {
}


bool VerifySVNR::verify(const char *svnrnumber, int len) {
bool VerifySVNR::verify(const char *svnrnumber, int len) const {
int var_len = len;
int sum = 0;
unsigned int i = 0, svnr_len = 10;
Expand Down
2 changes: 1 addition & 1 deletion src/operators/verify_svnr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class VerifySVNR : public Operator {
const std::string& input,
std::shared_ptr<RuleMessage> ruleMessage) override;

bool verify(const char *ssnumber, int len);
bool verify(const char *ssnumber, int len) const;

private:
Regex *m_re;
Expand Down
4 changes: 2 additions & 2 deletions src/parser/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ int Driver::addSecRule(std::unique_ptr<RuleWithActions> r) {
}

for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
Rules *rules = m_rulesSetPhases[i];
const Rules *rules = m_rulesSetPhases[i];
for (int j = 0; j < rules->size(); j++) {
RuleWithOperator *lr = dynamic_cast<RuleWithOperator *>(rules->at(j).get());
const RuleWithOperator *lr = dynamic_cast<RuleWithOperator *>(rules->at(j).get());
if (lr && lr->m_ruleId == rule->m_ruleId) {
m_parserError << "Rule id: " << std::to_string(rule->m_ruleId) \
<< " is duplicated" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/request_body_processor/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int JSON::addArgument(const std::string& value) {
std::string path;

for (size_t i = 0; i < m_containers.size(); i++) {
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
const JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
m_containers[i]);
path = path + m_containers[i]->m_name;
if (a != NULL) {
Expand Down
4 changes: 2 additions & 2 deletions src/rule_with_actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void RuleWithActions::executeTransformations(
std::shared_ptr<std::string>(new std::string(path))));
}

for (Action *a : m_transformations) {
for (const Action *a : m_transformations) {
if (a->m_isNone) {
none++;
}
Expand Down Expand Up @@ -406,7 +406,7 @@ void RuleWithActions::executeTransformations(
if (m_ruleId != b.first) {
continue;
}
Transformation *a = dynamic_cast<Transformation*>(b.second.get());
const Transformation *a = dynamic_cast<Transformation*>(b.second.get());
if (a->m_isNone) {
none++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rule_with_operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ inline void RuleWithOperator::getFinalVars(variables::Variables *vars,
bool RuleWithOperator::evaluate(Transaction *trans,
std::shared_ptr<RuleMessage> ruleMessage) {
bool globalRet = false;
variables::Variables *variables = this->m_variables;
const variables::Variables *variables = this->m_variables; // cppcheck-suppress unreadVariable ; false positive
bool recursiveGlobalRet;
bool containsBlock = hasBlockAction();
std::string eparam;
Expand Down
2 changes: 1 addition & 1 deletion src/rules_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ extern "C" RulesSet *msc_create_rules_set(void) {
}


extern "C" void msc_rules_dump(RulesSet *rules) {
extern "C" void msc_rules_dump(const RulesSet *rules) {
rules->dump();
}

Expand Down
4 changes: 2 additions & 2 deletions src/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ int Transaction::processResponseBody() {
int Transaction::appendResponseBody(const unsigned char *buf, size_t len) {
int current_size = this->m_responseBody.tellp();

std::set<std::string> &bi = \
const std::set<std::string> &bi = \
this->m_rules->m_responseBodyTypeToBeInspected.m_value;
auto t = bi.find(m_variableResponseContentType.m_value);
if (t == bi.end() && bi.empty() == false) {
Expand Down Expand Up @@ -2282,7 +2282,7 @@ extern "C" int msc_intervention(Transaction *transaction,
* @retval NULL Nothing was updated.
*
*/
extern "C" const char *msc_get_response_body(Transaction *transaction) {
extern "C" const char *msc_get_response_body(const Transaction *transaction) {
return transaction->getResponseBody();
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/regex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ std::list<SMatch> Regex::searchAll(const std::string& s) const {
rc = pcre2_match(m_pc, pcre2_s, s.length(),
offset, PCRE2_NO_JIT, match_data, NULL);
}
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data);
const PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data);
#else
const char *subject = s.c_str();
int ovector[OVECCOUNT];
Expand Down Expand Up @@ -207,7 +207,7 @@ RegexResult Regex::searchOneMatch(const std::string& s, std::vector<SMatchCaptur
if (m_pcje != 0 || rc == PCRE2_ERROR_JIT_STACKLIMIT) {
rc = pcre2_match(m_pc, pcre2_s, s.length(), 0, PCRE2_NO_JIT, match_data, match_context);
}
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data);
const PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data);
#else
const char *subject = s.c_str();
int ovector[OVECCOUNT];
Expand Down Expand Up @@ -261,7 +261,7 @@ RegexResult Regex::searchGlobal(const std::string& s, std::vector<SMatchCapture>
}
int rc = pcre2_match(m_pc, pcre2_s, s.length(),
startOffset, pcre2_options, match_data, match_context);
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data);
const PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(match_data);

#else
const char *subject = s.c_str();
Expand Down
2 changes: 1 addition & 1 deletion src/variables/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Env::evaluate(Transaction *transaction,
transaction->m_variableEnvs.insert(a);
}

for (auto& x : transaction->m_variableEnvs) {
for (const auto& x : transaction->m_variableEnvs) {
if (x.first != m_name && m_name.length() > 0) {
continue;
}
Expand Down
10 changes: 5 additions & 5 deletions src/variables/variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ Variable::Variable(const std::string &name)
}


Variable::Variable(Variable *var) :
Variable::Variable(const Variable *var) :
m_name(var->m_name),
m_collectionName(var->m_collectionName),
m_fullName(var->m_fullName) { }


void Variable::addsKeyExclusion(Variable *v) {
void Variable::addsKeyExclusion(const Variable *v) {
std::unique_ptr<KeyExclusion> r;
VariableModificatorExclusion *ve = \
const VariableModificatorExclusion *ve = \
dynamic_cast<VariableModificatorExclusion *>(v);
VariableRegex *vr;

Expand All @@ -76,12 +76,12 @@ void Variable::addsKeyExclusion(Variable *v) {
}


std::string operator+(const std::string &a, Variable *v) {
std::string operator+(const std::string &a, const Variable *v) {
return a + *v->m_fullName.get();
}


std::string operator+(const std::string &a, Variables *v) {
std::string operator+(const std::string &a, const Variables *v) {
std::string test;
for (const auto &b : *v) {
if (test.empty()) {
Expand Down
8 changes: 4 additions & 4 deletions src/variables/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ class VariableMonkeyResolution {
class Variable : public VariableMonkeyResolution {
public:
explicit Variable(const std::string &name);
explicit Variable(Variable *_name);
explicit Variable(const Variable *_name);
virtual ~Variable() { }


Expand All @@ -608,7 +608,7 @@ class Variable : public VariableMonkeyResolution {
}


void addsKeyExclusion(Variable *v);
void addsKeyExclusion(const Variable *v);


bool operator==(const Variable& b) const {
Expand Down Expand Up @@ -719,8 +719,8 @@ class VariableModificatorCount : public Variable {
};


std::string operator+(const std::string &a, modsecurity::variables::Variable *v);
std::string operator+(const std::string &a, modsecurity::variables::Variables *v);
std::string operator+(const std::string &a, const modsecurity::variables::Variable *v);
std::string operator+(const std::string &a, const modsecurity::variables::Variables *v);


} // namespace variables
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ char rules_file[] = "basic_rules.conf";

const char* const help_message = "Usage: benchmark [num_iterations|-h|-?|--help]";

int main(int argc, char *argv[]) {
int main(int argc, const char *argv[]) {

unsigned long long NUM_REQUESTS(1000000);

Expand Down
4 changes: 2 additions & 2 deletions test/optimization/optimization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char **argv) {
}


for (auto &x : files) {
for (const auto &x : files) {
std::cout << "Loading file: " << x << std::endl;
if (modsecRules->loadFromUri(x.c_str()) < 0) {
std::cout << "Not able to load the rules" << std::endl;
Expand Down Expand Up @@ -97,7 +97,7 @@ int main(int argc, char **argv) {
}

if (dynamic_cast<modsecurity::RuleWithOperator *>(z.get()) != nullptr) {
auto *rwo = dynamic_cast<modsecurity::RuleWithOperator *>(z.get());
const auto *rwo = dynamic_cast<modsecurity::RuleWithOperator *>(z.get());

std::string op = rwo->getOperatorName();
if (operators.count(op) > 0) {
Expand Down
6 changes: 3 additions & 3 deletions test/regression/regression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ void logCb(void *data, const void *msgv) {
}


void perform_unit_test(ModSecurityTest<RegressionTest> *test,
std::vector<RegressionTest *> *tests,
void perform_unit_test(const ModSecurityTest<RegressionTest> *test,
const std::vector<RegressionTest *> *tests,
ModSecurityTestResults<RegressionTestResult> *res, int *count) {

for (RegressionTest *t : *tests) {
Expand Down Expand Up @@ -380,7 +380,7 @@ void perform_unit_test(ModSecurityTest<RegressionTest> *test,
#endif
modsec_transaction->processLogging();

CustomDebugLog *d = reinterpret_cast<CustomDebugLog *>
const CustomDebugLog *d = reinterpret_cast<CustomDebugLog *>
(modsec_rules->m_debugLog);

if (d != NULL) {
Expand Down
Loading

0 comments on commit c6fbeca

Please sign in to comment.