1#include <qpdf/InputSource_private.hh>
2
3#include <qpdf/QIntC.hh>
4#include <qpdf/QTC.hh>
5#include <cstring>
6#include <stdexcept>
7
8using namespace std::literals;
9
10void
11InputSource::setLastOffset(qpdf_offset_t offset)
12{
13 this->last_offset = offset;
14}
15
…lines 16–69 unchanged (54 lines)
70 // specifically constructed to make sure we caught the edge cases in testing.
71
72 char buf[1025]; // size known to input_source.cc in libtests
73 // To enable us to guarantee null-termination, save an extra byte so that buf[size] is valid
74 // memory.
75 size_t size = sizeof(buf) - 1;
76 if ((strlen(start_chars) < 1) || (strlen(start_chars) > size)) {
77 throw std::logic_error(
78 "InputSource::findSource called with too small or too large of a character sequence");
79 }
80
81 char* p = nullptr;
82 qpdf_offset_t buf_offset = offset;
83 size_t bytes_read = 0;
84
85 // Guarantee that we return from this loop. Each time through, we either return, advance p, or
…lines 86–151 unchanged (66 lines)
152 ++p;
153 } else {
154 // Trigger reading the next block
155 p = buf + bytes_read;
156 }
157 }
158 throw std::logic_error("InputSource after while (true)");
159}
160
161bool
162InputSource::findLast(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
163{
164 bool found = false;
…lines 165–183 unchanged (19 lines)