-
Notifications
You must be signed in to change notification settings - Fork 1.7k
chore: fix cppcheck warning #3434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3/master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't say that I understand all the changes, but I didn't spot any obvious errors.
Below I attached the link of the failed action and a short description how to see them. I fixed all occurrences.
Here is the output of https://github.com/owasp-modsecurity/ModSecurity/actions/runs/16874871780/job/47804383442?pr=3432 Unfortunately it's hard to see where are the failed checks, probably you can download raw logs, extract them and find the pattern
Mostly those are type cast issues. There are a few new SonarCloud errors here, I'm going to fix them before I merge this PR. I'll let you know if I'm done. |
Here are the list of type cast issues:
plus the
|
Okay, I think I'm done. |
src/operators/rbl.cc
Outdated
if (addr->sa_family == AF_INET) { // only IPv4 address is allowed | ||
struct sockaddr_in *sin = reinterpret_cast<struct sockaddr_in *>(addr); | ||
auto sin = (struct sockaddr_in *) addr; // cppcheck-suppress[dangerousTypeCast] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you use a C++ cast here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I can't show the relevant SonarQube issue, because it shows only the current state (last analysis). As you mentioned there was a C++ type converter there: reinterpret_cast<struct sockaddr_in *>(addr);
- but SonarQube reported this cast can lead to an undefined behavior. So I could choose from two options: suppress cppcheck
warning or disable SonarQube check. I chose to suppress cppcheck
warning 😃
Note, that here we can't use either dynamic_cast<>
or static_cast<>
because they make cast between derived classes, but these types here are C structs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's see what's happen with commit 8b3269f.
|
Okay, after 62cb73f both |
what
This PR collects a few small fixes which solves the issues with current (2.18.0)
cppcheck
.Changes:
iss
was declared asstd::istream
and later it was converted unnecessaryhttps://
then we should read from stream. Note thatstd::stringstream
(case ofhttp
resource) andstd::ifstream
derived both fromstd::istream
reinterpret_cast<>
and add error report (if the socket type is notAF_INET
(IPv4))reinterpret_cast<>
test/cppcheck_suppressions.txt
why
There are a few warnings by
cppcheck
in recent PR's.references
See PR #3432.