Skip to content

Commit

Permalink
Fix wrong Tell() result from BufferedOutputStream in an edge case (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhztheplayer committed Feb 28, 2022
1 parent 9f876a6 commit f53137e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cpp/src/arrow/io/buffered.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class BufferedOutputStream::Impl : public BufferedBase {
RETURN_NOT_OK(FlushUnlocked());
DCHECK_EQ(buffer_pos_, 0);
if (nbytes >= buffer_size_) {
// Invalidate cached raw pos
raw_pos_ = -1;
// Direct write
if (buffer) {
return raw_->Write(buffer);
Expand Down
13 changes: 13 additions & 0 deletions cpp/src/arrow/io/buffered_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,19 @@ TEST_F(TestBufferedOutputStream, Tell) {
AssertTell(0);
}

TEST_F(TestBufferedOutputStream, Tell2) {
OpenBuffered();
AssertTell(0);

const std::string datastr = GenerateRandomData(10000);
const char* d = datastr.data();

ASSERT_OK(buffered_->Write(d, 5000));
AssertTell(5000);

ASSERT_OK(buffered_->Close());
}

TEST_F(TestBufferedOutputStream, TruncatesFile) {
OpenBuffered();

Expand Down

0 comments on commit f53137e

Please sign in to comment.