diff --git a/include/bit_vector.hpp b/include/bit_vector.hpp index ba0fb57..9cd515f 100644 --- a/include/bit_vector.hpp +++ b/include/bit_vector.hpp @@ -97,6 +97,7 @@ struct bit_vector // void append_bits(uint64_t bits, uint64_t len) { // check there are no spurious bits + assert(len <= 64); assert(len == 64 || (bits >> len) == 0); if (!len) return; uint64_t pos_in_word = m_num_bits & 63; diff --git a/include/compact_vector.hpp b/include/compact_vector.hpp index 59c1753..75db609 100644 --- a/include/compact_vector.hpp +++ b/include/compact_vector.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "essentials.hpp" @@ -253,7 +254,9 @@ struct compact_vector // assert(i < size()); uint64_t pos = i * m_width; const char* ptr = reinterpret_cast(m_data.data()); - return (*(reinterpret_cast(ptr + (pos >> 3))) >> (pos & 7)) & m_mask; + uint64_t word; + std::memcpy(&word, ptr + (pos >> 3), sizeof(uint64_t)); + return (word >> (pos & 7)) & m_mask; } uint64_t back() const { return operator[](size() - 1); }