Skip to content

Commit

Permalink
refactor: fix Sonar findings (philips-software#337)
Browse files Browse the repository at this point in the history
fix: cpp:S6232 well-defined type-punning method should be used instead of a union-based one
  • Loading branch information
rjaegers committed Jun 27, 2023
1 parent a294fb1 commit d809c17
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions services/network/NameResolverCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,13 @@ namespace services

std::array<uint8_t, 16> NameResolverCache::Hash(infra::BoundedConstString name) const
{
union
{
struct
{
std::array<uint8_t, 16> first;
std::array<uint8_t, 16> second;
} hash_parts;

std::array<uint8_t, 32> hash;
} result;

Sha256MbedTls sha256;
result.hash = sha256.Calculate(infra::StringAsByteRange(name));
const auto hash = sha256.Calculate(infra::StringAsByteRange(name));

std::array<uint8_t, 16> result;
infra::Copy(infra::Head(infra::MakeRange(hash), result.size()), infra::MakeRange(result));

return result.hash_parts.first;
return result;
}

void NameResolverCache::TryResolveNext()
Expand Down

0 comments on commit d809c17

Please sign in to comment.