Skip to content

Commit

Permalink
Do not serialize empty bytes with std::memcpy, to prevent memcpy from…
Browse files Browse the repository at this point in the history
…/to nullptr (even though size==0)
  • Loading branch information
eyalz800 committed May 5, 2023
1 parent 660ae01 commit d01dc49
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions zpp_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,10 @@ class basic_out
std::remove_cvref_t<decltype(*item.data())>>);

auto item_size_in_bytes = item.size_in_bytes();
if (!item_size_in_bytes) [[unlikely]] {
return {};
}

if constexpr (resizable) {
if (auto result = enlarge_for(item_size_in_bytes);
failure(result)) [[unlikely]] {
Expand Down Expand Up @@ -2596,6 +2600,10 @@ class in

auto size = m_data.size();
auto item_size_in_bytes = item.size_in_bytes();
if (!item_size_in_bytes) [[unlikely]] {
return {};
}

if (item_size_in_bytes > size - m_position) [[unlikely]] {
return std::errc::result_out_of_range;
}
Expand Down

0 comments on commit d01dc49

Please sign in to comment.