Skip to content

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

Merged
merged 9 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/operators/fuzzy_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool FuzzyHash::init(const std::string &param2, std::string *error) {
std::string resource = utils::find_resource(file, param2, &err);
iss = new std::ifstream(resource, std::ios::in);

if ((iss)->is_open() == false) {
if (iss->is_open() == false) {
error->assign("Failed to open file: " + m_param + ". " + err);
delete iss;
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/operators/inspect_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool InspectFile::init(const std::string &param2, std::string *error) {
m_file = utils::find_resource(m_param, param2, &err);
iss = new std::ifstream(m_file, std::ios::in);

if ((iss)->is_open() == false) {
if (iss->is_open() == false) {
error->assign("Failed to open file: " + m_param + ". " + err);
delete iss;
return false;
Expand Down
47 changes: 24 additions & 23 deletions src/operators/pm_from_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,33 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
std::vector<std::string> tokens = split(m_param, ' ');

for (const auto& token : tokens) {
if (! token.empty()) {
if (token.empty()) {
continue;
}

std::unique_ptr<std::istream> iss;
std::unique_ptr<std::istream> iss;

if (token.compare(0, 8, "https://") == 0) {
Utils::HttpsClient client;
bool ret = client.download(token);
if (ret == false) {
error->assign(client.error);
return false;
}
iss = std::make_unique<std::stringstream>(client.content);
} else {
std::string err;
std::string resource = utils::find_resource(token, config, &err);
auto file = std::make_unique<std::ifstream>(resource, std::ios::in);
if (file->is_open() == false) {
error->assign("Failed to open file: '" + token + "'. " + err);
return false;
}
iss = std::move(file);
if (token.compare(0, 8, "https://") == 0) {
Utils::HttpsClient client;
bool ret = client.download(token);
if (ret == false) {
error->assign(client.error);
return false;
}
iss = std::make_unique<std::stringstream>(client.content);
} else {
std::string err;
std::string resource = utils::find_resource(token, config, &err);
auto file = std::make_unique<std::ifstream>(resource, std::ios::in);
if (file->is_open() == false) {
error->assign("Failed to open file: '" + token + "'. " + err);
return false;
}
for (std::string line; std::getline(*iss, line); ) {
if (isComment(line) == false) {
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
}
iss = std::move(file);
}
for (std::string line; std::getline(*iss, line); ) {
if (isComment(line) == false) {
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/operators/rbl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,13 @@ bool Rbl::evaluate(Transaction *t, RuleWithActions *rule,
return false;
}

// NOSONAR
// SonarCloud suggested to use the init-statement to declare "addr" inside the if statement.
// I think that's not good here, because we need that in the else block
struct sockaddr *addr = info->ai_addr;
// NOSONAR
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]
furtherInfo(sin, ipStr, t, m_provider);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/variables/xml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void XML::evaluate(Transaction *t,
} else {
std::vector<actions::Action *> acts = rule->getActionsByName("xmlns", t);
for (auto &x : acts) {
actions::XmlNS *z = reinterpret_cast<actions::XmlNS *>(x);
actions::XmlNS *z = static_cast<actions::XmlNS *>(x);
if (xmlXPathRegisterNs(xpathCtx, reinterpret_cast<const xmlChar*>(z->m_scope.c_str()),
reinterpret_cast<const xmlChar*>(z->m_href.c_str())) != 0) {
ms_dbg_a(t, 1, "Failed to register XML namespace href \"" + \
Expand Down
Loading