diff --git a/src/common/bit_vector.hpp b/src/common/bit_vector.hpp index 83d49d3ace7..55403c5d35c 100644 --- a/src/common/bit_vector.hpp +++ b/src/common/bit_vector.hpp @@ -200,9 +200,7 @@ void BitVector<_b>::encode_data(bufferlist& bl, uint64_t byte_offset, bufferlist bit; bit.substr_of(m_data, byte_offset, len); - m_data_crcs[byte_offset / CEPH_PAGE_SIZE] = - ceph_crc32c(0, reinterpret_cast(bit.c_str()), - bit.length()); + m_data_crcs[byte_offset / CEPH_PAGE_SIZE] = bit.crc32c(0); bl.claim_append(bit); byte_offset += CEPH_PAGE_SIZE; @@ -388,11 +386,10 @@ typename BitVector<_b>::Reference& BitVector<_b>::Reference::operator=(uint8_t v uint64_t shift; this->m_bit_vector.compute_index(this->m_offset, &index, &shift); - // TODO: find out why bufferlist doesn't support char& operator[]() uint8_t mask = MASK << shift; - char* packed_data = this->m_bit_vector.m_data.c_str(); - uint8_t packed_value = (packed_data[index] & ~mask) | ((v << shift) & mask); - packed_data[index] = packed_value; + char packed_value = (this->m_bit_vector.m_data[index] & ~mask) | + ((v << shift) & mask); + this->m_bit_vector.m_data.copy_in(index, 1, &packed_value); return *this; } diff --git a/src/test/common/test_bit_vector.cc b/src/test/common/test_bit_vector.cc index 679b687252a..be31d257f94 100644 --- a/src/test/common/test_bit_vector.cc +++ b/src/test/common/test_bit_vector.cc @@ -202,27 +202,30 @@ TYPED_TEST(BitVectorTest, header_crc) { } TYPED_TEST(BitVectorTest, data_crc) { - typename TestFixture::bit_vector_t bit_vector; + typename TestFixture::bit_vector_t bit_vector1; + typename TestFixture::bit_vector_t bit_vector2; - uint64_t elements_per_byte = 8 / bit_vector.BIT_COUNT; - bit_vector.resize((CEPH_PAGE_SIZE + 1) * elements_per_byte); + uint64_t elements_per_byte = 8 / bit_vector1.BIT_COUNT; + bit_vector1.resize((CEPH_PAGE_SIZE + 1) * elements_per_byte); + bit_vector2.resize((CEPH_PAGE_SIZE + 1) * elements_per_byte); uint64_t byte_offset; uint64_t byte_length; - bit_vector.get_data_extents(0, bit_vector.size(), &byte_offset, &byte_length); + bit_vector1.get_data_extents(0, bit_vector1.size(), &byte_offset, + &byte_length); bufferlist data; - bit_vector.encode_data(data, byte_offset, byte_length); + bit_vector1.encode_data(data, byte_offset, byte_length); bufferlist::iterator data_it = data.begin(); - bit_vector.decode_data(data_it, byte_offset); + bit_vector1.decode_data(data_it, byte_offset); - bit_vector[bit_vector.size() - 1] = 1; + bit_vector2[bit_vector2.size() - 1] = 1; bufferlist dummy_data; - bit_vector.encode_data(dummy_data, byte_offset, byte_length); + bit_vector2.encode_data(dummy_data, byte_offset, byte_length); data_it = data.begin(); - ASSERT_THROW(bit_vector.decode_data(data_it, byte_offset), + ASSERT_THROW(bit_vector2.decode_data(data_it, byte_offset), buffer::malformed_input); }