Try to avoid any kind of type casting

This commit is contained in:
Ervin Hegedus 2025-08-12 21:05:31 +02:00
parent e879711d87
commit 8b3269f4d1
No known key found for this signature in database
GPG Key ID: 5FA5BC3F5EC41F61

View File

@ -226,14 +226,14 @@ 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
auto sin = (struct sockaddr_in *) addr; // cppcheck-suppress[dangerousTypeCast]
furtherInfo(sin, ipStr, t, m_provider);
struct sockaddr *addr = info->ai_addr; // NOSONAR
if (addr->sa_family == AF_INET) { // NOSONAR
struct sockaddr_in sin{}; // initialize an empty struct; we don't need port info
memcpy(&sin.sin_addr, addr->sa_data + 2, sizeof(sin.sin_addr));
sin.sin_family = AF_INET;
furtherInfo(&sin, ipStr, t, m_provider);
}
else {
ms_dbg_a(t, 7, "Unsupported address family: " + std::to_string(addr->sa_family));