Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8b3269f

Browse files
committed
Try to avoid any kind of type casting
1 parent e879711 commit 8b3269f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

‎src/operators/rbl.cc‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ bool Rbl::evaluate(Transaction *t, RuleWithActions *rule,
226226
return false;
227227
}
228228

229-
// NOSONAR
230229
// SonarCloud suggested to use the init-statement to declare "addr" inside the if statement.
231230
// I think that's not good here, because we need that in the else block
232-
struct sockaddr *addr = info->ai_addr;
233-
// NOSONAR
234-
if (addr->sa_family == AF_INET) { // only IPv4 address is allowed
235-
auto sin = (struct sockaddr_in *) addr; // cppcheck-suppress[dangerousTypeCast]
236-
furtherInfo(sin, ipStr, t, m_provider);
231+
struct sockaddr *addr = info->ai_addr; // NOSONAR
232+
if (addr->sa_family == AF_INET) { // NOSONAR
233+
struct sockaddr_in sin{}; // initialize an empty struct; we don't need port info
234+
memcpy(&sin.sin_addr, addr->sa_data + 2, sizeof(sin.sin_addr));
235+
sin.sin_family = AF_INET;
236+
furtherInfo(&sin, ipStr, t, m_provider);
237237
}
238238
else {
239239
ms_dbg_a(t, 7, "Unsupported address family: " + std::to_string(addr->sa_family));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /