diff --git a/cc/util/file_random_access_stream.cc b/cc/util/file_random_access_stream.cc index f0ddcc6c98b551144e6ecfad500c359c8fad62a2..ca869bd6d96b78d43189c05a9ddbc9b1e10c5407 100644 --- a/cc/util/file_random_access_stream.cc +++ b/cc/util/file_random_access_stream.cc @@ -58,9 +58,9 @@ Status FileRandomAccessStream::PRead(int64_t position, int count, return ToStatusF(util::error::INVALID_ARGUMENT, "dest_buffer must be non-null"); } - if (count < 0) { + if (count <= 0) { return ToStatusF(util::error::INVALID_ARGUMENT, - "count cannot be negative"); + "count must be positive"); } if (count > dest_buffer->allocated_size()) { return ToStatusF(util::error::INVALID_ARGUMENT, @@ -72,9 +72,6 @@ Status FileRandomAccessStream::PRead(int64_t position, int count, } crypto::tink::util::Status status = dest_buffer->set_size(count); if (!status.ok()) return status; - if (count == 0) { - return Status::OK; - } int read_count = pread(fd_, dest_buffer->get_mem_block(), count, position); if (read_count == 0) { dest_buffer->set_size(0).IgnoreError(); diff --git a/cc/util/file_random_access_stream_test.cc b/cc/util/file_random_access_stream_test.cc index b0d1307f2250520c58048de51e35227329fabbc4..134d02db6be9250181c3017aa5922aef06c3c0e5 100644 --- a/cc/util/file_random_access_stream_test.cc +++ b/cc/util/file_random_access_stream_test.cc @@ -75,7 +75,7 @@ void ReadAndVerifyChunk(RandomAccessStream* ra_stream, } TEST(FileRandomAccessStreamTest, ReadingStreams) { - for (auto stream_size : {0, 10, 100, 1000, 10000, 1000000}) { + for (auto stream_size : {1, 10, 100, 1000, 10000, 1000000}) { SCOPED_TRACE(absl::StrCat("stream_size = ", stream_size)); std::string file_contents; std::string filename = absl::StrCat(stream_size, "_reading_test.bin"); @@ -157,7 +157,7 @@ TEST(FileRandomAccessStreamTest, NegativeReadPosition) { } } -TEST(FileRandomAccessStreamTest, NegativeReadCount) { +TEST(FileRandomAccessStreamTest, NotPositiveReadCount) { for (auto stream_size : {0, 10, 100, 1000, 10000}) { std::string file_contents; std::string filename = absl::StrCat(stream_size, "_reading_test.bin"); @@ -166,7 +166,7 @@ TEST(FileRandomAccessStreamTest, NegativeReadCount) { auto ra_stream = absl::make_unique<util::FileRandomAccessStream>(input_fd); auto buffer = std::move(Buffer::New(42).ValueOrDie()); int64_t position = 0; - for (auto count : {-100, -10, -1}) { + for (auto count : {-100, -10, -1, 0}) { SCOPED_TRACE(absl::StrCat("stream_size = ", stream_size, " count = ", count)); auto status = ra_stream->PRead(position, count, buffer.get());