Skip to content

Commit 603975b

Browse files
author
MarcoFalke
committed
Merge #12770: Use explicit casting in cuckoocache's compute_hashes(...) to clarify integer conversion
9142dfe Use explicit casting in cuckoocache's compute_hashes(...) to clarify integer conversion (practicalswift) Pull request description: Use explicit casting in cuckoocache's `compute_hashes(...)` to clarify integer conversion. I discussed this code with the code's author @JeremyRubin who suggested patching it to avoid any confusion. At least one static analyzer incorrectly warns about a shift past bitwidth (UB) here, so this patch will help avoid confusion for human reviewers and static analyzers alike :-) Tree-SHA512: 0419ee31b422d2ffedbd1a100688ec0ff5b0c1690d6d92592f638ca8db07a21a9650cb467923108c6f14a38d2bf07d6e6c85d2d1d4b7da53ffe6919f94f32655
2 parents cd8e45b + 9142dfe commit 603975b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/cuckoocache.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ class cache
242242
*/
243243
inline std::array<uint32_t, 8> compute_hashes(const Element& e) const
244244
{
245-
return {{(uint32_t)((hash_function.template operator()<0>(e) * (uint64_t)size) >> 32),
246-
(uint32_t)((hash_function.template operator()<1>(e) * (uint64_t)size) >> 32),
247-
(uint32_t)((hash_function.template operator()<2>(e) * (uint64_t)size) >> 32),
248-
(uint32_t)((hash_function.template operator()<3>(e) * (uint64_t)size) >> 32),
249-
(uint32_t)((hash_function.template operator()<4>(e) * (uint64_t)size) >> 32),
250-
(uint32_t)((hash_function.template operator()<5>(e) * (uint64_t)size) >> 32),
251-
(uint32_t)((hash_function.template operator()<6>(e) * (uint64_t)size) >> 32),
252-
(uint32_t)((hash_function.template operator()<7>(e) * (uint64_t)size) >> 32)}};
245+
return {{(uint32_t)(((uint64_t)hash_function.template operator()<0>(e) * (uint64_t)size) >> 32),
246+
(uint32_t)(((uint64_t)hash_function.template operator()<1>(e) * (uint64_t)size) >> 32),
247+
(uint32_t)(((uint64_t)hash_function.template operator()<2>(e) * (uint64_t)size) >> 32),
248+
(uint32_t)(((uint64_t)hash_function.template operator()<3>(e) * (uint64_t)size) >> 32),
249+
(uint32_t)(((uint64_t)hash_function.template operator()<4>(e) * (uint64_t)size) >> 32),
250+
(uint32_t)(((uint64_t)hash_function.template operator()<5>(e) * (uint64_t)size) >> 32),
251+
(uint32_t)(((uint64_t)hash_function.template operator()<6>(e) * (uint64_t)size) >> 32),
252+
(uint32_t)(((uint64_t)hash_function.template operator()<7>(e) * (uint64_t)size) >> 32)}};
253253
}
254254

255255
/* end

0 commit comments

Comments
 (0)