aboutsummaryrefslogtreecommitdiff
path: root/src/common/Buffer.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-06-10 13:40:32 +0800
committercrupest <crupest@outlook.com>2024-06-10 23:48:32 +0800
commit2f5651cd1a1efb136179cdbcb3b29ed0cc11ca2a (patch)
tree400236cca0b1d28b0361f51c09ce4e2bf7d89d6c /src/common/Buffer.cpp
parent633c77d7cd2dd5cd22018aca17da1490e34d94ec (diff)
downloadcru-2f5651cd1a1efb136179cdbcb3b29ed0cc11ca2a.tar.gz
cru-2f5651cd1a1efb136179cdbcb3b29ed0cc11ca2a.tar.bz2
cru-2f5651cd1a1efb136179cdbcb3b29ed0cc11ca2a.zip
HALF WORK: still need to fix invalid size value in Buffer.
NEED TEST: BufferStream, AutoReadStream, SubProcess.
Diffstat (limited to 'src/common/Buffer.cpp')
-rw-r--r--src/common/Buffer.cpp10
1 files changed, 10 insertions, 0 deletions
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) {