Commit 3f2526d6 authored by Igor Sugak's avatar Igor Sugak Committed by Facebook Github Bot

fix implicit-integer-truncation UBSAN error in AtomicUtil-inl.h

Summary:
UndefinedBehaviorSanitizer: implicit-integer-truncation buck-out/dev/gen/folly/synchronization/atomic_util#header-mode-symlink-tree-with-header-map,headers/folly/synchronization/AtomicUtil-inl.h:115:28
```

Here both `mask` and the first argument in `std::atomic<..>::fetch_and` have type  `unsigned char`. Before bitwise not operation `mask` variable undergoes [integral promotion](https://en.cppreference.com/w/cpp/language/implicit_conversion#Integral_promotion) resulting in truncation error.

Since here this is intentional add a `static_cast` to be explicit about it.

Reviewed By: yfeldblum

Differential Revision: D19320340

fbshipit-source-id: 41c987c19b77fa21ee9aa83cf06dfc7cddba91c8
parent 3c6f1f78
......@@ -112,7 +112,7 @@ bool atomic_fetch_reset_default(
std::memory_order order) {
using Integer = decltype(atomic.load());
auto mask = Integer{0b1} << static_cast<Integer>(bit);
return (atomic.fetch_and(~mask, order) & mask);
return (atomic.fetch_and(static_cast<Integer>(~mask), order) & mask);
}
/**
......
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