Skip to content

Commit

Permalink
Fix alignment issue with heap_string
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Oct 11, 2023
1 parent d31dda3 commit 530b956
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/jsoncons/detail/heap_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace detail {
Extra extra() const { return this->extra_; }

heap_string(Extra extra, const Allocator& alloc)
: heap_string_base<Extra,Allocator>(extra, alloc), p_(nullptr), length_(0)
: heap_string_base<Extra,Allocator>(extra, alloc), p_(nullptr), length_(0), offset_(0)
{
}

Expand Down Expand Up @@ -145,6 +145,8 @@ namespace detail {

char* storage = align_up(q, align);

JSONCONS_ASSERT(storage >= q);

heap_string_type* ps = new(storage)heap_string_type(extra, byte_alloc);

auto psa = launder_cast<storage_t*>(storage);
Expand All @@ -154,7 +156,7 @@ namespace detail {
p[length] = 0;
ps->p_ = std::pointer_traits<typename heap_string_type::pointer>::pointer_to(*p);
ps->length_ = length;
ps->offset_ = (uint16_t)(q - storage);
ps->offset_ = (uint16_t)(storage - q);
return std::pointer_traits<pointer>::pointer_to(*ps);
}

Expand Down

0 comments on commit 530b956

Please sign in to comment.