diff options
| author | luigi1111 <luigi1111w@gmail.com> | 2020-06-08 14:05:05 -0500 |
|---|---|---|
| committer | luigi1111 <luigi1111w@gmail.com> | 2020-06-08 14:05:05 -0500 |
| commit | 967285a9faef89e1ce7f24697f336959a34b845c (patch) | |
| tree | 02ce65889142d0fc79a21453a13b1565fcfe9c24 /contrib/epee/src/byte_slice.cpp | |
| parent | 09667700e8ea1a51052a89f382d36ed87e9cb749 (diff) | |
| parent | 29e563bb1ed0be0f358235faf1b1848b222b584d (diff) | |
| download | monzero-core-967285a9faef89e1ce7f24697f336959a34b845c.tar.gz monzero-core-967285a9faef89e1ce7f24697f336959a34b845c.tar.xz monzero-core-967285a9faef89e1ce7f24697f336959a34b845c.zip | |
Merge pull request #6522
29e563b Fixed bugs for take_slice and byte_stream->byte_slice (vtnerd)
Diffstat (limited to 'contrib/epee/src/byte_slice.cpp')
| -rw-r--r-- | contrib/epee/src/byte_slice.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/contrib/epee/src/byte_slice.cpp b/contrib/epee/src/byte_slice.cpp index 99c37fae3..12cc83e6c 100644 --- a/contrib/epee/src/byte_slice.cpp +++ b/contrib/epee/src/byte_slice.cpp @@ -173,9 +173,14 @@ namespace epee byte_slice::byte_slice(byte_stream&& stream) noexcept : storage_(nullptr), portion_(stream.data(), stream.size()) { - std::uint8_t* const data = stream.take_buffer().release() - sizeof(raw_byte_slice); - new (data) raw_byte_slice{}; - storage_.reset(reinterpret_cast<raw_byte_slice*>(data)); + if (stream.size()) + { + std::uint8_t* const data = stream.take_buffer().release() - sizeof(raw_byte_slice); + new (data) raw_byte_slice{}; + storage_.reset(reinterpret_cast<raw_byte_slice*>(data)); + } + else + portion_ = nullptr; } byte_slice::byte_slice(byte_slice&& source) noexcept @@ -205,14 +210,17 @@ namespace epee byte_slice byte_slice::take_slice(const std::size_t max_bytes) noexcept { byte_slice out{}; - std::uint8_t const* const ptr = data(); - out.portion_ = {ptr, portion_.remove_prefix(max_bytes)}; - if (portion_.empty()) - out.storage_ = std::move(storage_); // no atomic inc/dec - else - out = {storage_.get(), out.portion_}; + if (max_bytes) + { + std::uint8_t const* const ptr = data(); + out.portion_ = {ptr, portion_.remove_prefix(max_bytes)}; + if (portion_.empty()) + out.storage_ = std::move(storage_); // no atomic inc/dec + else + out = {storage_.get(), out.portion_}; + } return out; } |
