fix: cppcheck warnings#3508
Conversation
Thanks - unfortunately the |
There was a problem hiding this comment.
Pull request overview
This PR addresses new cppcheck (2.20.0) warnings across core and public-header code by improving const-correctness, tightening variable scope, and adding targeted suppressions while attempting to preserve ABI via wrapper overloads.
Changes:
- Add
constoverloads for multiple methods (with non-const wrappers kept for ABI compatibility where needed). - Reduce unnecessary initializations/copies and narrow variable lifetimes.
- Add an inline
cppcheck-suppressfor a platform-dependent unused label warning.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/fuzzer/afl_fuzzer.cc | Avoids an extra std::string copy by binding to a const reference. |
| src/variables/variable.h | Makes KeyExclusions::toOmit const and keeps a non-const wrapper. |
| src/unique_id.cc | Adds an inline cppcheck-suppress on a label to silence a configuration warning. |
| src/transaction.cc | Removes redundant empty-string initialization for ckey. |
| src/rules_set_properties.cc | Narrows ucode scope into the mapping != NULL block. |
| src/rules_set.cc | Adds RulesSet::getParserError() const and adjusts rules pointer constness. |
| src/audit_log/audit_log.cc | Adds AuditLog::isRelevant(...) const and a wrapper with old signature. |
| src/anchored_set_variable.cc | Adds const overloads for resolve helpers and ABI-preserving wrappers. |
| src/actions/transformations/url_decode_uni.cc | Narrows Code scope to the unicode-map branch. |
| headers/modsecurity/rules_set.h | Declares getParserError() const in the public header. |
| headers/modsecurity/audit_log.h | Declares isRelevant(...) const in the public header. |
| headers/modsecurity/anchored_set_variable.h | Declares new const overloads and documents ABI-compat wrappers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
|
@theseion could you review this again? All tests have passed, all |
theseion
left a comment
There was a problem hiding this comment.
There's still one SonarQube warning.


what
This PR contains several
cppcheckwarnings' fixes:toOmit()toconstinsrc/variables/variable.hresolve()andresolveRegularExpression()functions toconstinanchored_set_variable.cc|hCodevariable to inner block inurl_decode_uni.ccisRelevant()toconstinaudit_log.cc|hgetParserError()toconstinrules_set.cc|hucodevariable to inner block inrules_set_properties.ccckeyintransaction.cccppcheck-suppressflag to avoid warning inunique_id.ccafl_fuzzer.ccwhy
cppcheck's new version (2.20.0) warned these issues.references
See #3504's failed job
other notes
where the modified functions' signature has changed, I added a wrapper with an old signature to keep the symbols in ABI. Therefore these changes don't break the library's ABI.