Commit d3858daa authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

fix an UBSAN failure in DistributedMutex

Summary:
Fix an `invalid-shift-base` UndefinedBehaviorSanitizer failure.
Previously all of the DistributedMutex-inl.h tests would fail with the
following message on my system:

  runtime error: left shift of 94500093116194837 by 8 places cannot be
  represented in type 'long'

It might be slightly nicer in the long run to change this code to use
`std::chrono::duration<std::uint64_t, std::nano>` throughout rather than
`std::chrono::nanoseconds`.  Currently the `time()` function casts the
`uint64_t` value returned by `folly::hardware_timestamp()` into a signed
value.

Reviewed By: yfeldblum, aary

Differential Revision: D14180336

fbshipit-source-id: b199ae22d951162dc6f31d7f1c41a7d67cbcc935
parent 679a76a9
...@@ -216,7 +216,7 @@ Type* extractAddress(std::uintptr_t from) { ...@@ -216,7 +216,7 @@ Type* extractAddress(std::uintptr_t from) {
*/ */
inline std::uint64_t strip(std::chrono::nanoseconds t) { inline std::uint64_t strip(std::chrono::nanoseconds t) {
auto time = t.count(); auto time = t.count();
return time << 8; return static_cast<std::uint64_t>(time) << 8;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment