Skip to content

Commit

Permalink
Prevent undefined behavior from left shifting into sign bit when offs…
Browse files Browse the repository at this point in the history
…et is 31
  • Loading branch information
daniel-j-h committed Feb 8, 2016
1 parent fa85299 commit b8d20df
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/util/shared_memory_vector_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ template <> class SharedMemoryWrapper<bool>
{
const std::size_t bucket = index / 32;
const unsigned offset = static_cast<unsigned>(index % 32);
return m_ptr[bucket] & (1 << offset);
return m_ptr[bucket] & (1u << offset);
}

std::size_t size() const { return m_size; }
Expand All @@ -110,7 +110,7 @@ template <> class SharedMemoryWrapper<bool>
BOOST_ASSERT_MSG(index < m_size, "invalid size");
const unsigned bucket = index / 32;
const unsigned offset = index % 32;
return m_ptr[bucket] & (1 << offset);
return m_ptr[bucket] & (1u << offset);
}

template <typename T>
Expand Down

0 comments on commit b8d20df

Please sign in to comment.