Prevent undefined behavior from left shifting into sign bit when offset is 31

This commit is contained in:
Daniel J. Hofmann 2016-02-05 17:54:59 +01:00
parent fa8529949b
commit b8d20dfe99

View File

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