bit_util: bug: Infinite loop in HighestSetBit

This commit is contained in:
MerryMage 2018-01-24 16:15:17 +00:00
parent 3caf192f60
commit 33bba6028c

View file

@ -101,6 +101,9 @@ inline int HighestSetBit(T value) {
template <typename T> template <typename T>
inline size_t LowestSetBit(T value) { inline size_t LowestSetBit(T value) {
auto x = static_cast<std::make_unsigned_t<T>>(value); auto x = static_cast<std::make_unsigned_t<T>>(value);
if (x == 0)
return BitSize<T>();
size_t result = 0; size_t result = 0;
while ((x & 1) == 0) { while ((x & 1) == 0) {
x >>= 1; x >>= 1;