Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/core/src/clp/BufferReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ auto BufferReader::try_read(char* buf, size_t num_bytes_to_read, size_t& num_byt
throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__);
}

if (0 == num_bytes_to_read) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concern, when only I read this code, I thought the copy doesn't handle 0 bytes copy.

Then after reading the case description, I realized that the issue is when (0 == remaining_data_size).

If I were to write this code, I might put this if-clause under (0 == remaining_data_size). That said, I feel it's also ok to handle the 0 bytes read earlier so the function doesn't do unnecessary work.

Up to you which you choose.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I put it this way mainly for efficiency. I could move it inside the if block

num_bytes_read = 0;
return ErrorCode_Success;
}

auto remaining_data_size = get_remaining_data_size();
if (0 == remaining_data_size) {
return ErrorCode_EndOfFile;
Expand Down