diff --git a/persistent-data/buffer.h b/persistent-data/buffer.h index 5f35cd8..45e2390 100644 --- a/persistent-data/buffer.h +++ b/persistent-data/buffer.h @@ -32,19 +32,19 @@ //---------------------------------------------------------------- namespace persistent_data { - // Joe has buffer<> in other parts of the code, so... uint32_t const DEFAULT_BUFFER_SIZE = 4096; // Allocate buffer of Size with Alignment imposed. // - // Allocation needs to be on the heap in order to provide alignment guarantees! - // + // Allocation needs to be on the heap in order to provide alignment + // guarantees. + // // Alignment must be a power of two. - template class buffer : private boost::noncopyable { public: typedef boost::shared_ptr ptr; + typedef boost::shared_ptr const_ptr; unsigned char &operator[](unsigned index) { check_index(index); diff --git a/unit-tests/buffer_t.cc b/unit-tests/buffer_t.cc index 248ad0a..a5d98a5 100644 --- a/unit-tests/buffer_t.cc +++ b/unit-tests/buffer_t.cc @@ -82,12 +82,20 @@ BOOST_AUTO_TEST_CASE(buffer_8_a_8_access) BOOST_CHECK_EQUAL((*b)[0], '\0'); } +BOOST_AUTO_TEST_CASE(buffer_8_a_8_oob) +{ + uint32_t const sz = 8, align = 8; + buffer::ptr b = create_buffer(); + + BOOST_CHECK_NO_THROW((*b)[8] = 0); +} + BOOST_AUTO_TEST_CASE(buffer_8_a_8_const_access) { uint32_t const sz = 8, align = 8; - buffer::ptr const b = create_buffer(); + buffer::const_ptr b = create_buffer(); - (*b)[0] = 0; // Compile time error accessing read-only location + // (*b)[0] = 0; // Compile time error accessing read-only location } // 8 byte buffer size, varying alignment from 1 - 7