Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lihuiba committed Dec 5, 2023
1 parent 6148c4c commit 21c8ee0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ IStream::ReadAll IStream::readall(size_t min_buf, size_t max_buf) {
ReadAll buf;
buf.size = 0;
ssize_t capacity = min_buf;
buf.ptr.reset((char*)malloc(capacity));
auto ptr = (char*)malloc(capacity);
if (!ptr)
LOG_ERROR_RETURN(ENOBUFS, buf, "no enough buffer memory");
buf.ptr.reset(ptr);
while(true) {
ssize_t ret = this->read((char*)buf.ptr.get() + buf.size, capacity - buf.size);
if (ret < 0) {
Expand All @@ -22,7 +25,7 @@ IStream::ReadAll IStream::readall(size_t min_buf, size_t max_buf) {
if (unlikely(buf.size == capacity)) {
if (capacity >= max_buf) {
buf.size = -buf.size;
LOG_ERROR_RETURN(ENOBUFS, {nullptr}, "content in stream is too large to fit into buffer");
LOG_ERROR_RETURN(ENOBUFS, buf, "content size in stream exceeds upper limit ", max_buf);
}
auto ptr = realloc(buf.ptr.get(), capacity *= 2);
buf.ptr.reset(ptr);
Expand Down

0 comments on commit 21c8ee0

Please sign in to comment.