const-ify some references (satisfy cppcheck)

This commit is contained in:
Martin Vierula 2023-10-27 06:20:01 -07:00
parent b9836bcaa4
commit 36adc58ea3
No known key found for this signature in database
GPG Key ID: F2FC4E45883BCBA4
11 changed files with 14 additions and 14 deletions

View File

@ -47,7 +47,7 @@ class AnchoredSetVariableTranslationProxy {
VariableValue *newVariableValue = new VariableValue(name, &l->at(i)->getKey(), &l->at(i)->getKey());
const VariableValue *oldVariableValue = l->at(i);
l->at(i) = newVariableValue;
for (auto &oldOrigin : oldVariableValue->getOrigin()) {
for (const auto &oldOrigin : oldVariableValue->getOrigin()) {
std::unique_ptr<VariableOrigin> newOrigin(new VariableOrigin);
newOrigin->m_length = oldVariableValue->getKey().size();
newOrigin->m_offset = oldOrigin->m_offset - oldVariableValue->getKey().size() - 1;

View File

@ -62,7 +62,7 @@ class VariableValue {
m_keyWithCollection(o->m_keyWithCollection),
m_value(o->m_value)
{
for (auto &i : o->m_orign) {
for (const auto &i : o->m_orign) {
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
origin->m_offset = i->m_offset;
origin->m_length = i->m_length;

View File

@ -30,7 +30,7 @@ bool RuleRemoveById::init(std::string *error) {
std::string what(m_parser_payload, 15, m_parser_payload.size() - 15);
bool added = false;
std::vector<std::string> toRemove = utils::string::ssplit(what, ' ');
for (std::string &a : toRemove) {
for (const std::string &a : toRemove) {
std::string b = modsecurity::utils::string::parserSanitizer(a);
if (b.size() == 0) {
continue;

View File

@ -289,7 +289,7 @@ bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
return true;
}
for (RuleMessage &i : transaction->m_rulesMessages) {
for (const RuleMessage &i : transaction->m_rulesMessages) {
if (i.m_noAuditLog == false) {
saveAnyway = true;
break;

View File

@ -38,7 +38,7 @@ std::string RuleMessage::_details(const RuleMessage *rm) {
msg.append(" [maturity \"" + std::to_string(rm->m_maturity) + "\"]");
msg.append(" [accuracy \"" + std::to_string(rm->m_accuracy) + "\"]");
for (auto &a : rm->m_tags) {
for (const auto &a : rm->m_tags) {
msg.append(" [tag \"" + utils::string::toHexIfNeeded(a, true) + "\"]");
}

View File

@ -228,7 +228,7 @@ bool RuleWithOperator::evaluate(Transaction *trans,
// FIXME: Make a class runTimeException to handle this cases.
for (auto &i : trans->m_ruleRemoveById) {
for (const auto &i : trans->m_ruleRemoveById) {
if (m_ruleId != i) {
continue;
}
@ -236,7 +236,7 @@ bool RuleWithOperator::evaluate(Transaction *trans,
" was skipped due to a ruleRemoveById action...");
return true;
}
for (auto &i : trans->m_ruleRemoveByIdRange) {
for (const auto &i : trans->m_ruleRemoveByIdRange) {
if (!(i.first <= m_ruleId && i.second >= m_ruleId)) {
continue;
}

View File

@ -122,7 +122,7 @@ bool RulesExceptions::loadUpdateTargetById(double id,
bool RulesExceptions::load(const std::string &a, std::string *error) {
bool added = false;
std::vector<std::string> toRemove = utils::string::ssplit(a, ' ');
for (std::string &r : toRemove) {
for (const std::string &r : toRemove) {
std::string b = modsecurity::utils::string::parserSanitizer(r);
if (b.size() == 0) {
continue;

View File

@ -162,7 +162,7 @@ int RulesSet::evaluate(int phase, Transaction *t) {
}
bool remove_rule = false;
if (ruleWithActions && m_exceptions.m_remove_rule_by_msg.empty() == false) {
for (auto &z : m_exceptions.m_remove_rule_by_msg) {
for (const auto &z : m_exceptions.m_remove_rule_by_msg) {
if (ruleWithActions->containsMsg(z, t) == true) {
ms_dbg_a(t, 9, "Skipped rule id '" \
+ ruleWithActions->getReference() \
@ -177,7 +177,7 @@ int RulesSet::evaluate(int phase, Transaction *t) {
}
if (ruleWithActions && m_exceptions.m_remove_rule_by_tag.empty() == false) {
for (auto &z : m_exceptions.m_remove_rule_by_tag) {
for (const auto &z : m_exceptions.m_remove_rule_by_tag) {
if (ruleWithActions->containsTag(z, t) == true) {
ms_dbg_a(t, 9, "Skipped rule id '" \
+ ruleWithActions->getReference() \
@ -193,7 +193,7 @@ int RulesSet::evaluate(int phase, Transaction *t) {
if (ruleWithActions) {
for (auto &z : t->m_ruleRemoveByTag) {
for (const auto &z : t->m_ruleRemoveByTag) {
if (ruleWithActions->containsTag(z, t) == true) {
ms_dbg_a(t, 9, "Skipped rule id '" \
+ ruleWithActions->getReference() \

View File

@ -1242,7 +1242,7 @@ int Transaction::processResponseBody() {
return true;
}
std::set<std::string> &bi = \
const std::set<std::string> &bi = \
m_rules->m_responseBodyTypeToBeInspected.m_value;
auto t = bi.find(m_variableResponseContentType.m_value);
if (t == bi.end()

View File

@ -69,7 +69,7 @@ void RemoteUser::evaluate(Transaction *transaction,
var = new VariableValue(&l2->at(0)->getKeyWithCollection(),
&transaction->m_variableRemoteUser);
for (auto &i : l2->at(0)->getOrigin()) {
for (const auto &i : l2->at(0)->getOrigin()) {
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
origin->m_offset = i->m_offset;
origin->m_length = i->m_length;

View File

@ -83,7 +83,7 @@ std::string operator+(const std::string &a, Variable *v) {
std::string operator+(const std::string &a, Variables *v) {
std::string test;
for (auto &b : *v) {
for (const auto &b : *v) {
if (test.empty()) {
test = std::string("") + b;
} else {