Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gibber9809 committed Dec 6, 2024
1 parent 47b0cc0 commit 7aff0c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 2 additions & 3 deletions components/core/src/clp/CheckpointReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace clp {
auto CheckpointReader::try_seek_from_begin(size_t pos) -> ErrorCode {
m_cur_pos = pos > m_checkpoint ? m_checkpoint : pos;
if (auto const rc = m_reader->try_seek_from_begin(m_cur_pos);
ErrorCode_Success != rc) {
if (auto const rc = m_reader->try_seek_from_begin(m_cur_pos); ErrorCode_Success != rc) {
return rc;
}
if (m_cur_pos >= m_checkpoint) {
Expand All @@ -18,7 +17,7 @@ auto CheckpointReader::try_read(char* buf, size_t num_bytes_to_read, size_t& num
if (m_cur_pos == m_checkpoint) {
return ErrorCode_EndOfFile;
}

if ((m_cur_pos + num_bytes_to_read) > m_checkpoint) {
num_bytes_to_read = m_checkpoint - m_cur_pos;
}
Expand Down
5 changes: 3 additions & 2 deletions components/core/src/clp/CheckpointReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class CheckpointReader : public ReaderInterface {
explicit CheckpointReader(ReaderInterface* reader, size_t checkpoint)
: m_reader(reader),
m_checkpoint(checkpoint) {
if (nullptr != m_reader) {
m_cur_pos = m_reader->get_pos();
if (nullptr == m_reader) {
throw ReaderInterface::OperationFailed(ErrorCode_BadParam, __FILE__, __LINE__);
}
m_cur_pos = m_reader->get_pos();
if (m_cur_pos > m_checkpoint) {
throw ReaderInterface::OperationFailed(ErrorCode_BadParam, __FILE__, __LINE__);
}
Expand Down
5 changes: 5 additions & 0 deletions components/core/tests/test-CheckpointReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ TEST_CASE("Test Checkpoint Reader", "[CheckpointReader]") {
REQUIRE(1 == num_bytes_read);
REQUIRE(1 == string_reader.get_pos());
REQUIRE(1 == checkpoint_reader.get_pos());
rc = checkpoint_reader.try_read(buf, 1, num_bytes_read);
REQUIRE(clp::ErrorCode_EndOfFile == rc);
REQUIRE(0 == num_bytes_read);
REQUIRE(1 == string_reader.get_pos());
REQUIRE(1 == checkpoint_reader.get_pos());
}

SECTION("CheckpointReader does allow reads before checkpoint.") {
Expand Down

0 comments on commit 7aff0c6

Please sign in to comment.