diff --git a/src/misc/bitvect.cc b/src/misc/bitvect.cc index 874df0bf2..88f8d0b02 100644 --- a/src/misc/bitvect.cc +++ b/src/misc/bitvect.cc @@ -160,7 +160,7 @@ namespace spot bitvect_array* bva = new(mem) bitvect_array(vectcount, bvsize); // Initialize all the bitvect instances. for (size_t i = 0; i < vectcount; ++i) - new(bva->storage_ + i * bvsize) bitvect(bitcount, n); + new(bva->storage() + i * bvsize) bitvect(bitcount, n); return bva; } diff --git a/src/misc/bitvect.hh b/src/misc/bitvect.hh index 2342bf993..838c8a950 100644 --- a/src/misc/bitvect.hh +++ b/src/misc/bitvect.hh @@ -456,6 +456,17 @@ namespace spot SPOT_LOCAL bitvect_array(const bitvect_array&) SPOT_DELETED; SPOT_LOCAL void operator=(const bitvect_array&) SPOT_DELETED; + // Extra storage has been allocated at the end of the struct. + char* storage() + { + return reinterpret_cast(this) + sizeof(*this); + } + + const char* storage() const + { + return reinterpret_cast(this) + sizeof(*this); + } + public: ~bitvect_array() { @@ -473,14 +484,14 @@ namespace spot bitvect& at(const size_t index) { assert(index < size_); - return *reinterpret_cast(storage_ + index * bvsize_); + return *reinterpret_cast(storage() + index * bvsize_); } /// Return the bit-vector at \a index. const bitvect& at(const size_t index) const { assert(index < size_); - return *reinterpret_cast(storage_ + index * bvsize_); + return *reinterpret_cast(storage() + index * bvsize_); } friend SPOT_API bitvect_array* @@ -495,7 +506,6 @@ namespace spot private: size_t size_; size_t bvsize_; - char storage_[0]; }; /// @}