Skip to content

Commit e9bf9ad

Browse files
committed
Add const modifier to range-based for loops
1 parent 12671d1 commit e9bf9ad

File tree

11 files changed

+29
-29
lines changed

11 files changed

+29
-29
lines changed

src/actions/block.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace actions {
3232
bool Block::evaluate(RuleWithActions *rule, Transaction *transaction, RuleMessage &ruleMessage) {
3333
ms_dbg_a(transaction, 8, "Marking request as disruptive.");
3434

35-
for (auto &a : transaction->m_rules->m_defaultActions[rule->getPhase()]) {
35+
for (const auto& a : transaction->m_rules->m_defaultActions[rule->getPhase()]) {
3636
if (a->isDisruptive() == false) {
3737
continue;
3838
}

src/collection/backend/in_memory-per_process.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void InMemoryPerProcess::resolveMultiMatches(const std::string& var,
155155
const std::shared_lock lock(m_mutex); // read lock (shared access)
156156

157157
if (keySize == 0) {
158-
for (auto &i : m_map) {
158+
for (const auto &i : m_map) {
159159
if (ke.toOmit(i.first)) {
160160
continue;
161161
}

src/engine/lua.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ int Lua::getvars(lua_State *L) {
297297
variables::Variable::stringMatchResolveMulti(t, varname, &l);
298298

299299
lua_newtable(L);
300-
for (auto* i : l) {
300+
for (const auto *i : l) {
301301
lua_pushnumber(L, idx);
302302
lua_newtable(L);
303303

src/rule_with_actions.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void RuleWithActions::executeActionsIndependentOfChainedRuleResult(Transaction *
209209
a->evaluate(this, trans);
210210
}
211211

212-
for (auto &b :
212+
for (const auto& b :
213213
trans->m_rules->m_exceptions.m_action_pre_update_target_by_id) {
214214
if (m_ruleId != b.first) {
215215
continue;
@@ -262,7 +262,7 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans,
262262
a->evaluate(this, trans, ruleMessage);
263263
}
264264

265-
for (auto &b :
265+
for (const auto& b :
266266
trans->m_rules->m_exceptions.m_action_pos_update_target_by_id) {
267267
if (m_ruleId != b.first) {
268268
continue;
@@ -373,7 +373,7 @@ void RuleWithActions::executeTransformations(
373373
// Notice that first we make sure that won't be a t:none
374374
// on the target rule.
375375
if (none == 0) {
376-
for (auto &a : trans->m_rules->m_defaultActions[getPhase()]) {
376+
for (const auto& a : trans->m_rules->m_defaultActions[getPhase()]) {
377377
if (a->action_kind \
378378
!= actions::Action::Kind::RunTimeBeforeMatchAttemptKind) {
379379
continue;
@@ -400,7 +400,7 @@ void RuleWithActions::executeTransformations(
400400

401401
// FIXME: It can't be something different from transformation. Sort this
402402
// on rules compile time.
403-
for (auto &b :
403+
for (const auto& b :
404404
trans->m_rules->m_exceptions.m_action_pre_update_target_by_id) {
405405
if (m_ruleId != b.first) {
406406
continue;
@@ -412,7 +412,7 @@ void RuleWithActions::executeTransformations(
412412
}
413413
}
414414

415-
for (auto &b :
415+
for (const auto& b :
416416
trans->m_rules->m_exceptions.m_action_pre_update_target_by_id) {
417417
if (m_ruleId != b.first) {
418418
continue;
@@ -442,7 +442,7 @@ void RuleWithActions::executeTransformations(
442442

443443

444444
bool RuleWithActions::containsTag(const std::string& name, Transaction *t) {
445-
for (auto &tag : m_actionsTag) {
445+
for (const auto &tag : m_actionsTag) {
446446
if (tag != NULL && tag->getName(t) == name) {
447447
return true;
448448
}
@@ -459,17 +459,17 @@ bool RuleWithActions::containsMsg(const std::string& name, Transaction *t) {
459459
std::vector<actions::Action *> RuleWithActions::getActionsByName(const std::string& name,
460460
const Transaction *trans) {
461461
std::vector<actions::Action *> ret;
462-
for (auto &z : m_actionsRuntimePos) {
462+
for (const auto &z : m_actionsRuntimePos) {
463463
if (*z->m_name.get() == name) {
464464
ret.push_back(z);
465465
}
466466
}
467-
for (auto &z : m_transformations) {
467+
for (const auto& z : m_transformations) {
468468
if (*z->m_name.get() == name) {
469469
ret.push_back(z);
470470
}
471471
}
472-
for (auto &b :
472+
for (const auto& b :
473473
trans->m_rules->m_exceptions.m_action_pre_update_target_by_id) {
474474
if (m_ruleId != b.first) {
475475
continue;
@@ -479,7 +479,7 @@ std::vector<actions::Action *> RuleWithActions::getActionsByName(const std::stri
479479
ret.push_back(z);
480480
}
481481
}
482-
for (auto &b :
482+
for (const auto& b :
483483
trans->m_rules->m_exceptions.m_action_pos_update_target_by_id) {
484484
if (m_ruleId != b.first) {
485485
continue;

src/rule_with_operator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ bool RuleWithOperator::evaluate(Transaction *trans,
252252

253253
getFinalVars(&vars, &exclusion, trans);
254254

255-
for (auto &var : vars) {
255+
for (const auto &var : vars) {
256256
std::vector<const VariableValue *> e;
257257
if (!var) {
258258
continue;

src/rules_exceptions.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool RulesExceptions::contains(int a) {
195195
}
196196
}
197197

198-
for (auto& z : m_ranges) {
198+
for (const auto& z : m_ranges) {
199199
if (z.first <= a && z.second >= a) {
200200
return true;
201201
}
@@ -212,42 +212,42 @@ bool RulesExceptions::merge(RulesExceptions *from) {
212212
return ret;
213213
}
214214
}
215-
for (auto& b : from->m_ranges) {
215+
for (const auto& b : from->m_ranges) {
216216
bool ret = addRange(b.first, b.second);
217217
if (ret == false) {
218218
return ret;
219219
}
220220
}
221221

222-
for (auto &p : from->m_variable_update_target_by_tag) {
222+
for (const auto &p : from->m_variable_update_target_by_tag) {
223223
m_variable_update_target_by_tag.emplace(
224224
std::pair<std::shared_ptr<std::string>,
225225
std::shared_ptr<variables::Variable>>(p.first,
226226
p.second));
227227
}
228228

229-
for (auto &p : from->m_variable_update_target_by_msg) {
229+
for (const auto &p : from->m_variable_update_target_by_msg) {
230230
m_variable_update_target_by_msg.emplace(
231231
std::pair<std::shared_ptr<std::string>,
232232
std::shared_ptr<variables::Variable>>(p.first,
233233
p.second));
234234
}
235235

236-
for (auto &p : from->m_variable_update_target_by_id) {
236+
for (const auto &p : from->m_variable_update_target_by_id) {
237237
m_variable_update_target_by_id.emplace(
238238
std::pair<double,
239239
std::shared_ptr<variables::Variable>>(p.first,
240240
p.second));
241241
}
242242

243-
for (auto &p : from->m_action_pos_update_target_by_id) {
243+
for (const auto &p : from->m_action_pos_update_target_by_id) {
244244
m_action_pos_update_target_by_id.emplace(
245245
std::pair<double,
246246
std::shared_ptr<actions::Action>>(p.first,
247247
p.second));
248248
}
249249

250-
for (auto &p : from->m_action_pre_update_target_by_id) {
250+
for (const auto &p : from->m_action_pre_update_target_by_id) {
251251
m_action_pre_update_target_by_id.emplace(
252252
std::pair<double,
253253
std::shared_ptr<actions::Action>>(p.first,

src/run_time_string.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ std::string RunTimeString::evaluate(Transaction *t) {
5353

5454
std::string RunTimeString::evaluate(Transaction *t, Rule *r) {
5555
std::string s;
56-
for (auto &z : m_elements) {
56+
for (const auto& z : m_elements) {
5757
if (z->m_string.size() > 0) {
5858
s.append(z->m_string);
5959
} else if (z->m_var != NULL && t != NULL) {

src/transaction.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ std::string Transaction::toJSON(int parts) {
17001700
reinterpret_cast<const unsigned char*>("messages"),
17011701
strlen("messages"));
17021702
yajl_gen_array_open(g);
1703-
for (auto& a : m_rulesMessages) {
1703+
for (const auto& a : m_rulesMessages) {
17041704
yajl_gen_map_open(g);
17051705
LOGFY_ADD("message", a.m_message);
17061706
yajl_gen_string(g,
@@ -1721,7 +1721,7 @@ std::string Transaction::toJSON(int parts) {
17211721
reinterpret_cast<const unsigned char*>("tags"),
17221722
strlen("tags"));
17231723
yajl_gen_array_open(g);
1724-
for (auto& b : a.m_tags) {
1724+
for (const auto& b : a.m_tags) {
17251725
yajl_gen_string(g,
17261726
reinterpret_cast<const unsigned char*>(b.data()),
17271727
b.length());

src/variables/variable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class KeyExclusions : public std::deque<std::unique_ptr<KeyExclusion>> {
155155
}
156156

157157
bool toOmit(std::string a) {
158-
for (auto &z : *this) {
158+
for (const auto& z : *this) {
159159
if (z->match(a)) {
160160
return true;
161161
}

test/regression/regression.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void perform_unit_test(const ModSecurityTest<RegressionTest> &test,
115115
const std::vector<std::unique_ptr<RegressionTest>> &tests,
116116
ModSecurityTestResults<RegressionTestResult> *res, int *count)
117117
{
118-
for (auto &t : tests) {
118+
for (const auto &t : tests) {
119119
ModSecurityTestResults<RegressionTest> r;
120120
RegressionTestResult *testRes = new RegressionTestResult();
121121

0 commit comments

Comments
 (0)