Skip to content

Commit 3b5d34e

Browse files
committed
Fix cppcheck warnings in anchored variables
1 parent 43accb3 commit 3b5d34e

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

headers/modsecurity/anchored_set_variable.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,26 @@ class AnchoredSetVariable : public std::unordered_multimap<std::string,
8484

8585
void setCopy(std::string key, std::string value, size_t offset);
8686

87+
void resolve(std::vector<const VariableValue *> *l) const;
88+
void resolve(std::vector<const VariableValue *> *l,
89+
const variables::KeyExclusions &ke) const;
90+
91+
// keep the old signatures for ABI compatibility
8792
void resolve(std::vector<const VariableValue *> *l);
8893
void resolve(std::vector<const VariableValue *> *l,
8994
variables::KeyExclusions &ke);
9095

9196
void resolve(const std::string &key,
9297
std::vector<const VariableValue *> *l);
9398

99+
void resolveRegularExpression(Utils::Regex *r,
100+
std::vector<const VariableValue *> *l) const;
101+
102+
void resolveRegularExpression(Utils::Regex *r,
103+
std::vector<const VariableValue *> *l,
104+
const variables::KeyExclusions &ke) const;
105+
106+
// keep the old signatures for ABI compatibility
94107
void resolveRegularExpression(Utils::Regex *r,
95108
std::vector<const VariableValue *> *l);
96109

src/anchored_set_variable.cc

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,22 @@ void AnchoredSetVariable::set(const std::string &key,
6767

6868

6969
void AnchoredSetVariable::resolve(
70-
std::vector<const VariableValue *> *l) {
70+
std::vector<const VariableValue *> *l) const {
7171
for (const auto& x : *this) {
7272
l->insert(l->begin(), new VariableValue(x.second));
7373
}
7474
}
7575

7676

77+
void AnchoredSetVariable::resolve(
78+
std::vector<const VariableValue *> *l) {
79+
static_cast<const AnchoredSetVariable&>(*this).resolve(l);
80+
}
81+
82+
7783
void AnchoredSetVariable::resolve(
7884
std::vector<const VariableValue *> *l,
79-
variables::KeyExclusions &ke) {
85+
const variables::KeyExclusions &ke) const {
8086
for (const auto& x : *this) {
8187
if (!ke.toOmit(x.first)) {
8288
l->insert(l->begin(), new VariableValue(x.second));
@@ -88,6 +94,13 @@ void AnchoredSetVariable::resolve(
8894
}
8995

9096

97+
void AnchoredSetVariable::resolve(
98+
std::vector<const VariableValue *> *l,
99+
variables::KeyExclusions &ke) { // cppcheck-suppress constParameterReference
100+
static_cast<const AnchoredSetVariable&>(*this).resolve(l, ke);
101+
}
102+
103+
91104
void AnchoredSetVariable::resolve(const std::string &key,
92105
std::vector<const VariableValue *> *l) {
93106
auto range = this->equal_range(key);
@@ -109,7 +122,7 @@ std::unique_ptr<std::string> AnchoredSetVariable::resolveFirst(
109122

110123

111124
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
112-
std::vector<const VariableValue *> *l) {
125+
std::vector<const VariableValue *> *l) const {
113126
for (const auto& x : *this) {
114127
int ret = Utils::regex_search(x.first, *r);
115128
if (ret <= 0) {
@@ -120,9 +133,15 @@ void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
120133
}
121134

122135

136+
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
137+
std::vector<const VariableValue *> *l) {
138+
static_cast<const AnchoredSetVariable&>(*this).resolveRegularExpression(r, l);
139+
}
140+
141+
123142
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
124143
std::vector<const VariableValue *> *l,
125-
variables::KeyExclusions &ke) {
144+
const variables::KeyExclusions &ke) const {
126145
for (const auto& x : *this) {
127146
int ret = Utils::regex_search(x.first, *r);
128147
if (ret <= 0) {
@@ -138,4 +157,11 @@ void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
138157
}
139158

140159

160+
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
161+
std::vector<const VariableValue *> *l,
162+
variables::KeyExclusions &ke) { // cppcheck-suppress constParameterReference
163+
static_cast<const AnchoredSetVariable&>(*this).resolveRegularExpression(r, l);
164+
}
165+
166+
141167
} // namespace modsecurity

src/variables/variable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class KeyExclusions : public std::deque<std::unique_ptr<KeyExclusion>> {
163163
return false;
164164
}
165165

166-
bool toOmit(std::string a) {
166+
bool toOmit(std::string a) { // cppcheck-suppress passedByValue
167167
return static_cast<const KeyExclusions&>(*this).toOmit(a);
168168
}
169169
};

0 commit comments

Comments
 (0)