diff --git a/src/util/SmallHeap.hpp b/src/util/SmallHeap.hpp index 8a6ff9290..213d36958 100644 --- a/src/util/SmallHeap.hpp +++ b/src/util/SmallHeap.hpp @@ -11,8 +11,10 @@ namespace util { template - inline T read_int_le(const uint8_t* src, size_t offset=0) { - return dataio::le2h(*(reinterpret_cast(src) + offset)); + inline T read_int_le(const uint8_t* src, ptrdiff_t offset=0) { + T tmp; + std::memcpy(&tmp, src + offset * sizeof(T), sizeof(T)); + return dataio::le2h(tmp); } /// @brief Simple heap implementation for memory-optimal sparse array of @@ -87,8 +89,7 @@ namespace util { std::memset(found, 0, entrySize); return found; } - this->free(found); - return allocate(index, size); + free(found); } for (size_t i = 0; i < entriesCount; i++) { auto data = buffer.data() + offset; @@ -110,9 +111,12 @@ namespace util { entriesCount++; auto data = buffer.data() + offset; - *reinterpret_cast(data) = dataio::h2le(index); + + Tindex indexTmp = dataio::h2le(index); + Tsize sizeTmp = dataio::h2le(size); + std::memcpy(data, &indexTmp, sizeof(Tindex)); data += sizeof(Tindex); - *reinterpret_cast(data) = dataio::h2le(size); + std::memcpy(data, &sizeTmp, sizeof(Tsize)); return data + sizeof(Tsize); } @@ -147,7 +151,8 @@ namespace util { ubyte* dst = out.data(); const ubyte* src = buffer.data(); - *reinterpret_cast(dst) = dataio::h2le(entriesCount); + Tindex countTmp = dataio::h2le(entriesCount); + std::memcpy(dst, &countTmp, sizeof(Tindex)); dst += sizeof(Tindex); std::memcpy(dst, src, buffer.size());