Skip to content

Commit 376c984

Browse files
committed
fix seek; use seek
1 parent f515331 commit 376c984

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/odr/internal/cfb/cfb_util.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ReaderBuffer final : public std::streambuf {
1717
ReaderBuffer(const impl::CompoundFileReader &reader,
1818
const impl::CompoundFileEntry &entry,
1919
std::unique_ptr<std::istream> stream,
20-
const std::size_t buffer_size = 4098)
20+
const std::size_t buffer_size = 4096)
2121
: m_reader{&reader}, m_entry{&entry}, m_stream{std::move(stream)},
2222
m_buffer(buffer_size, '\0') {}
2323

@@ -37,6 +37,11 @@ class ReaderBuffer final : public std::streambuf {
3737
return traits_type::to_int_type(*gptr());
3838
}
3939

40+
std::streampos seekpos(const std::streampos sp,
41+
const std::ios_base::openmode which) override {
42+
return seekoff(sp, std::ios_base::beg, which);
43+
}
44+
4045
std::streampos seekoff(const std::streamoff off,
4146
const std::ios_base::seekdir dir,
4247
const std::ios_base::openmode which) override {
@@ -49,9 +54,14 @@ class ReaderBuffer final : public std::streambuf {
4954
if (dir == std::ios_base::beg) {
5055
new_pos = off;
5156
} else if (dir == std::ios_base::cur) {
52-
new_pos = m_offset - (egptr() - gptr()) + off;
57+
const std::streampos current_pos =
58+
static_cast<std::streampos>(m_offset) +
59+
static_cast<std::streampos>(gptr() - eback());
60+
new_pos = current_pos + off;
5361
} else if (dir == std::ios_base::end) {
54-
new_pos = m_entry->size + off;
62+
new_pos = static_cast<std::streampos>(m_entry->size) + off;
63+
} else {
64+
throw std::logic_error("Invalid seek direction");
5565
}
5666

5767
if (new_pos < 0 || static_cast<std::uint64_t>(new_pos) > m_entry->size) {

src/odr/internal/zip/zip_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ReaderBuffer final : public std::streambuf {
1414
public:
1515
ReaderBuffer(std::shared_ptr<const Archive> archive,
1616
mz_zip_reader_extract_iter_state *iter,
17-
const std::size_t buffer_size = 4098)
17+
const std::size_t buffer_size = 4096)
1818
: m_archive{std::move(archive)}, m_buffer(buffer_size, '\0') {
1919
if (m_archive == nullptr) {
2020
throw NullPointerError("ReaderBuffer: archive is nullptr");

test/src/internal/oldms/oldms_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ TEST(OldMs, test) {
7777
std::cout << "first_text_offset " << first_text_offset << std::endl;
7878

7979
const auto document_stream = files.open("/WordDocument").stream();
80-
document_stream->ignore(first_text_offset);
80+
document_stream->seekg(first_text_offset);
8181
const std::string first_text =
8282
internal::util::stream::read(*document_stream, first_text_length);
8383
std::cout << "first_text " << first_text << std::endl;

0 commit comments

Comments
 (0)