From 2f5651cd1a1efb136179cdbcb3b29ed0cc11ca2a Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 10 Jun 2024 13:40:32 +0800 Subject: HALF WORK: still need to fix invalid size value in Buffer. NEED TEST: BufferStream, AutoReadStream, SubProcess. --- src/common/Buffer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/common/Buffer.cpp') diff --git a/src/common/Buffer.cpp b/src/common/Buffer.cpp index af0871ca..e37fddc7 100644 --- a/src/common/Buffer.cpp +++ b/src/common/Buffer.cpp @@ -58,6 +58,8 @@ void Buffer::AssignBytes(Index dst_offset, std::byte* src, Index src_offset, } void Buffer::ResizeBuffer(Index new_size, bool preserve_used) { + CheckSize(new_size); + if (new_size == 0) { Delete_(); ptr_ = nullptr; @@ -83,6 +85,8 @@ void Buffer::ResizeBuffer(Index new_size, bool preserve_used) { Index Buffer::PushFront(const std::byte* other, Index other_size, bool use_memmove) { + CheckSize(other_size); + auto copy_size = std::min(used_begin_, other_size); if (copy_size) { @@ -105,6 +109,8 @@ bool Buffer::PushBack(std::byte b) { Index Buffer::PushBack(const std::byte* other, Index other_size, bool use_memmove) { + CheckSize(other_size); + auto copy_size = std::min(size_ - used_end_, other_size); if (copy_size) { @@ -117,12 +123,16 @@ Index Buffer::PushBack(const std::byte* other, Index other_size, } Index Buffer::PopFront(Index size) { + CheckSize(size); + auto move = std::min(used_begin_, size); used_begin_ -= move; return move; } Index Buffer::PopFront(std::byte* buffer, Index size, bool use_memmove) { + CheckSize(size); + auto pop_size = std::min(GetUsedSize(), size); if (pop_size) { -- cgit v1.2.3