Skip to content

Commit

Permalink
Avoid unaligned memory access
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed May 17, 2024
1 parent 416b0d3 commit 91f9c4d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion elf/icf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ using Digest = std::array<uint8_t, HASH_SIZE>;
namespace std {
template <> struct hash<Digest> {
size_t operator()(const Digest &k) const {
return *(int64_t *)&k[0];
static_assert(sizeof(size_t) <= HASH_SIZE);
size_t val;
memcpy(&val, k.data(), sizeof(size_t));
return val;
}
};
}
Expand Down

0 comments on commit 91f9c4d

Please sign in to comment.