Commit c916dcf9733b8fbb928b30ada7fab4d4e1b78b2b

Authored by m-holger
1 parent 2cb2412f

Add new protected inline method Pipeline::next

Also, tidy pipeline constructors and make subclasses final where possible.
include/qpdf/Pipeline.hh
@@ -98,13 +98,19 @@ class QPDF_DLL_CLASS Pipeline @@ -98,13 +98,19 @@ class QPDF_DLL_CLASS Pipeline
98 protected: 98 protected:
99 QPDF_DLL 99 QPDF_DLL
100 Pipeline* getNext(bool allow_null = false); 100 Pipeline* getNext(bool allow_null = false);
  101 + QPDF_DLL
  102 + Pipeline*
  103 + next() const noexcept
  104 + {
  105 + return next_;
  106 + }
101 std::string identifier; 107 std::string identifier;
102 108
103 private: 109 private:
104 Pipeline(Pipeline const&) = delete; 110 Pipeline(Pipeline const&) = delete;
105 Pipeline& operator=(Pipeline const&) = delete; 111 Pipeline& operator=(Pipeline const&) = delete;
106 112
107 - Pipeline* next; 113 + Pipeline* next_;
108 }; 114 };
109 115
110 #endif // PIPELINE_HH 116 #endif // PIPELINE_HH
include/qpdf/Pl_Count.hh
@@ -57,8 +57,8 @@ class QPDF_DLL_CLASS Pl_Count: public Pipeline @@ -57,8 +57,8 @@ class QPDF_DLL_CLASS Pl_Count: public Pipeline
57 Members(Members const&) = delete; 57 Members(Members const&) = delete;
58 58
59 // Must be qpdf_offset_t, not size_t, to handle writing more than size_t can handle. 59 // Must be qpdf_offset_t, not size_t, to handle writing more than size_t can handle.
60 - qpdf_offset_t count;  
61 - unsigned char last_char; 60 + qpdf_offset_t count{0};
  61 + unsigned char last_char{'\0'};
62 }; 62 };
63 63
64 std::shared_ptr<Members> m; 64 std::shared_ptr<Members> m;
include/qpdf/Pl_Function.hh
@@ -19,6 +19,10 @@ @@ -19,6 +19,10 @@
19 #ifndef PL_FUNCTION_HH 19 #ifndef PL_FUNCTION_HH
20 #define PL_FUNCTION_HH 20 #define PL_FUNCTION_HH
21 21
  22 +#include <qpdf/Pipeline.hh>
  23 +
  24 +#include <functional>
  25 +
22 // This pipeline calls an arbitrary function with whatever data is passed to it. This pipeline can 26 // This pipeline calls an arbitrary function with whatever data is passed to it. This pipeline can
23 // be reused. 27 // be reused.
24 // 28 //
@@ -29,11 +33,6 @@ @@ -29,11 +33,6 @@
29 // 33 //
30 // It is okay to keep calling write() after a previous write throws an exception as long as the 34 // It is okay to keep calling write() after a previous write throws an exception as long as the
31 // delegated function allows it. 35 // delegated function allows it.
32 -  
33 -#include <qpdf/Pipeline.hh>  
34 -  
35 -#include <functional>  
36 -  
37 class QPDF_DLL_CLASS Pl_Function: public Pipeline 36 class QPDF_DLL_CLASS Pl_Function: public Pipeline
38 { 37 {
39 public: 38 public:
include/qpdf/Pl_QPDFTokenizer.hh
@@ -64,7 +64,7 @@ class QPDF_DLL_CLASS Pl_QPDFTokenizer: public Pipeline @@ -64,7 +64,7 @@ class QPDF_DLL_CLASS Pl_QPDFTokenizer: public Pipeline
64 Members(); 64 Members();
65 Members(Members const&) = delete; 65 Members(Members const&) = delete;
66 66
67 - QPDFObjectHandle::TokenFilter* filter; 67 + QPDFObjectHandle::TokenFilter* filter{nullptr};
68 QPDFTokenizer tokenizer; 68 QPDFTokenizer tokenizer;
69 Pl_Buffer buf; 69 Pl_Buffer buf;
70 }; 70 };
include/qpdf/Pl_RunLength.hh
@@ -59,9 +59,9 @@ class QPDF_DLL_CLASS Pl_RunLength: public Pipeline @@ -59,9 +59,9 @@ class QPDF_DLL_CLASS Pl_RunLength: public Pipeline
59 Members(Members const&) = delete; 59 Members(Members const&) = delete;
60 60
61 action_e action; 61 action_e action;
62 - state_e state; 62 + state_e state{st_top};
63 unsigned char buf[128]; 63 unsigned char buf[128];
64 - unsigned int length; 64 + unsigned int length{0};
65 std::string out; 65 std::string out;
66 }; 66 };
67 67
libqpdf/Pipeline.cc
@@ -5,18 +5,18 @@ @@ -5,18 +5,18 @@
5 5
6 Pipeline::Pipeline(char const* identifier, Pipeline* next) : 6 Pipeline::Pipeline(char const* identifier, Pipeline* next) :
7 identifier(identifier), 7 identifier(identifier),
8 - next(next) 8 + next_(next)
9 { 9 {
10 } 10 }
11 11
12 Pipeline* 12 Pipeline*
13 Pipeline::getNext(bool allow_null) 13 Pipeline::getNext(bool allow_null)
14 { 14 {
15 - if ((this->next == nullptr) && (!allow_null)) { 15 + if (!next_ && !allow_null) {
16 throw std::logic_error( 16 throw std::logic_error(
17 this->identifier + ": Pipeline::getNext() called on pipeline with no next"); 17 this->identifier + ": Pipeline::getNext() called on pipeline with no next");
18 } 18 }
19 - return this->next; 19 + return next_;
20 } 20 }
21 21
22 std::string 22 std::string
libqpdf/Pl_AES_PDF.cc
@@ -18,14 +18,11 @@ Pl_AES_PDF::Pl_AES_PDF( @@ -18,14 +18,11 @@ Pl_AES_PDF::Pl_AES_PDF(
18 Pipeline(identifier, next), 18 Pipeline(identifier, next),
19 crypto(QPDFCryptoProvider::getImpl()), 19 crypto(QPDFCryptoProvider::getImpl()),
20 encrypt(encrypt), 20 encrypt(encrypt),
21 - cbc_mode(true),  
22 - first(true),  
23 - offset(0),  
24 - key_bytes(key_bytes),  
25 - use_zero_iv(false),  
26 - use_specified_iv(false),  
27 - disable_padding(false) 21 + key_bytes(key_bytes)
28 { 22 {
  23 + if (!next) {
  24 + throw std::logic_error("Attempt to create Pl_AES_PDF with nullptr as next");
  25 + }
29 this->key = std::make_unique<unsigned char[]>(key_bytes); 26 this->key = std::make_unique<unsigned char[]>(key_bytes);
30 std::memcpy(this->key.get(), key, key_bytes); 27 std::memcpy(this->key.get(), key, key_bytes);
31 std::memset(this->inbuf, 0, this->buf_size); 28 std::memset(this->inbuf, 0, this->buf_size);
@@ -120,7 +117,7 @@ Pl_AES_PDF::finish() @@ -120,7 +117,7 @@ Pl_AES_PDF::finish()
120 flush(!this->disable_padding); 117 flush(!this->disable_padding);
121 } 118 }
122 this->crypto->rijndael_finalize(); 119 this->crypto->rijndael_finalize();
123 - getNext()->finish(); 120 + next()->finish();
124 } 121 }
125 122
126 void 123 void
@@ -157,7 +154,7 @@ Pl_AES_PDF::flush(bool strip_padding) @@ -157,7 +154,7 @@ Pl_AES_PDF::flush(bool strip_padding)
157 // output stream. 154 // output stream.
158 initializeVector(); 155 initializeVector();
159 if (!(this->use_zero_iv || this->use_specified_iv)) { 156 if (!(this->use_zero_iv || this->use_specified_iv)) {
160 - getNext()->write(this->cbc_block, this->buf_size); 157 + next()->write(this->cbc_block, this->buf_size);
161 } 158 }
162 } else if (this->use_zero_iv || this->use_specified_iv) { 159 } else if (this->use_zero_iv || this->use_specified_iv) {
163 // Initialize vector with zeroes; zero vector was not written to the beginning of 160 // Initialize vector with zeroes; zero vector was not written to the beginning of
@@ -196,5 +193,5 @@ Pl_AES_PDF::flush(bool strip_padding) @@ -196,5 +193,5 @@ Pl_AES_PDF::flush(bool strip_padding)
196 } 193 }
197 } 194 }
198 this->offset = 0; 195 this->offset = 0;
199 - getNext()->write(this->outbuf, bytes); 196 + next()->write(this->outbuf, bytes);
200 } 197 }
libqpdf/Pl_ASCII85Decoder.cc
@@ -5,11 +5,11 @@ @@ -5,11 +5,11 @@
5 #include <stdexcept> 5 #include <stdexcept>
6 6
7 Pl_ASCII85Decoder::Pl_ASCII85Decoder(char const* identifier, Pipeline* next) : 7 Pl_ASCII85Decoder::Pl_ASCII85Decoder(char const* identifier, Pipeline* next) :
8 - Pipeline(identifier, next),  
9 - pos(0),  
10 - eod(0) 8 + Pipeline(identifier, next)
11 { 9 {
12 - memset(this->inbuf, 117, 5); 10 + if (!next) {
  11 + throw std::logic_error("Attempt to create Pl_ASCII85Decoder with nullptr as next");
  12 + }
13 } 13 }
14 14
15 void 15 void
@@ -52,7 +52,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) @@ -52,7 +52,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len)
52 QTC::TC("libtests", "Pl_ASCII85Decoder read z"); 52 QTC::TC("libtests", "Pl_ASCII85Decoder read z");
53 unsigned char zeroes[4]; 53 unsigned char zeroes[4];
54 memset(zeroes, '\0', 4); 54 memset(zeroes, '\0', 4);
55 - getNext()->write(zeroes, 4); 55 + next()->write(zeroes, 4);
56 } 56 }
57 break; 57 break;
58 58
@@ -97,12 +97,12 @@ Pl_ASCII85Decoder::flush() @@ -97,12 +97,12 @@ Pl_ASCII85Decoder::flush()
97 this->pos = 0; 97 this->pos = 0;
98 memset(this->inbuf, 117, 5); 98 memset(this->inbuf, 117, 5);
99 99
100 - getNext()->write(outbuf, t); 100 + next()->write(outbuf, t);
101 } 101 }
102 102
103 void 103 void
104 Pl_ASCII85Decoder::finish() 104 Pl_ASCII85Decoder::finish()
105 { 105 {
106 flush(); 106 flush();
107 - getNext()->finish(); 107 + next()->finish();
108 } 108 }
libqpdf/Pl_ASCIIHexDecoder.cc
@@ -5,13 +5,11 @@ @@ -5,13 +5,11 @@
5 #include <stdexcept> 5 #include <stdexcept>
6 6
7 Pl_ASCIIHexDecoder::Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next) : 7 Pl_ASCIIHexDecoder::Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next) :
8 - Pipeline(identifier, next),  
9 - pos(0),  
10 - eod(false) 8 + Pipeline(identifier, next)
11 { 9 {
12 - this->inbuf[0] = '0';  
13 - this->inbuf[1] = '0';  
14 - this->inbuf[2] = '\0'; 10 + if (!next) {
  11 + throw std::logic_error("Attempt to create Pl_ASCIIHexDecoder with nullptr as next");
  12 + }
15 } 13 }
16 14
17 void 15 void
@@ -85,12 +83,12 @@ Pl_ASCIIHexDecoder::flush() @@ -85,12 +83,12 @@ Pl_ASCIIHexDecoder::flush()
85 this->inbuf[1] = '0'; 83 this->inbuf[1] = '0';
86 this->inbuf[2] = '\0'; 84 this->inbuf[2] = '\0';
87 85
88 - getNext()->write(&ch, 1); 86 + next()->write(&ch, 1);
89 } 87 }
90 88
91 void 89 void
92 Pl_ASCIIHexDecoder::finish() 90 Pl_ASCIIHexDecoder::finish()
93 { 91 {
94 flush(); 92 flush();
95 - getNext()->finish(); 93 + next()->finish();
96 } 94 }
libqpdf/Pl_Base64.cc
@@ -25,12 +25,11 @@ to_i(int i) @@ -25,12 +25,11 @@ to_i(int i)
25 25
26 Pl_Base64::Pl_Base64(char const* identifier, Pipeline* next, action_e action) : 26 Pl_Base64::Pl_Base64(char const* identifier, Pipeline* next, action_e action) :
27 Pipeline(identifier, next), 27 Pipeline(identifier, next),
28 - action(action),  
29 - pos(0),  
30 - end_of_data(false),  
31 - finished(false) 28 + action(action)
32 { 29 {
33 - reset(); 30 + if (!next) {
  31 + throw std::logic_error("Attempt to create Pl_Base64 with nullptr as next");
  32 + }
34 } 33 }
35 34
36 void 35 void
@@ -125,7 +124,7 @@ Pl_Base64::flush_decode() @@ -125,7 +124,7 @@ Pl_Base64::flush_decode()
125 to_uc(0xff & outval), 124 to_uc(0xff & outval),
126 }; 125 };
127 126
128 - getNext()->write(out, QIntC::to_size(3 - pad)); 127 + next()->write(out, QIntC::to_size(3 - pad));
129 } 128 }
130 129
131 void 130 void
@@ -158,7 +157,7 @@ Pl_Base64::flush_encode() @@ -158,7 +157,7 @@ Pl_Base64::flush_encode()
158 for (size_t i = 0; i < 3 - this->pos; ++i) { 157 for (size_t i = 0; i < 3 - this->pos; ++i) {
159 out[3 - i] = '='; 158 out[3 - i] = '=';
160 } 159 }
161 - getNext()->write(out, 4); 160 + next()->write(out, 4);
162 } 161 }
163 162
164 void 163 void
@@ -176,7 +175,7 @@ Pl_Base64::finish() @@ -176,7 +175,7 @@ Pl_Base64::finish()
176 flush(); 175 flush();
177 } 176 }
178 this->finished = true; 177 this->finished = true;
179 - getNext()->finish(); 178 + next()->finish();
180 } 179 }
181 180
182 void 181 void
libqpdf/Pl_Buffer.cc
@@ -25,8 +25,8 @@ Pl_Buffer::write(unsigned char const* buf, size_t len) @@ -25,8 +25,8 @@ Pl_Buffer::write(unsigned char const* buf, size_t len)
25 m->data.append(reinterpret_cast<char const*>(buf), len); 25 m->data.append(reinterpret_cast<char const*>(buf), len);
26 m->ready = false; 26 m->ready = false;
27 27
28 - if (getNext(true)) {  
29 - getNext()->write(buf, len); 28 + if (next()) {
  29 + next()->write(buf, len);
30 } 30 }
31 } 31 }
32 32
@@ -34,8 +34,8 @@ void @@ -34,8 +34,8 @@ void
34 Pl_Buffer::finish() 34 Pl_Buffer::finish()
35 { 35 {
36 m->ready = true; 36 m->ready = true;
37 - if (getNext(true)) {  
38 - getNext()->finish(); 37 + if (next()) {
  38 + next()->finish();
39 } 39 }
40 } 40 }
41 41
libqpdf/Pl_Concatenate.cc
1 #include <qpdf/Pl_Concatenate.hh> 1 #include <qpdf/Pl_Concatenate.hh>
2 2
  3 +#include <stdexcept>
  4 +
3 Pl_Concatenate::Pl_Concatenate(char const* identifier, Pipeline* next) : 5 Pl_Concatenate::Pl_Concatenate(char const* identifier, Pipeline* next) :
4 Pipeline(identifier, next) 6 Pipeline(identifier, next)
5 { 7 {
  8 + if (!next) {
  9 + throw std::logic_error("Attempt to create Pl_Concatenate with nullptr as next");
  10 + }
6 } 11 }
7 12
8 Pl_Concatenate::~Pl_Concatenate() // NOLINT (modernize-use-equals-default) 13 Pl_Concatenate::~Pl_Concatenate() // NOLINT (modernize-use-equals-default)
@@ -13,7 +18,7 @@ Pl_Concatenate::~Pl_Concatenate() // NOLINT (modernize-use-equals-default) @@ -13,7 +18,7 @@ Pl_Concatenate::~Pl_Concatenate() // NOLINT (modernize-use-equals-default)
13 void 18 void
14 Pl_Concatenate::write(unsigned char const* data, size_t len) 19 Pl_Concatenate::write(unsigned char const* data, size_t len)
15 { 20 {
16 - getNext()->write(data, len); 21 + next()->write(data, len);
17 } 22 }
18 23
19 void 24 void
@@ -24,5 +29,5 @@ Pl_Concatenate::finish() @@ -24,5 +29,5 @@ Pl_Concatenate::finish()
24 void 29 void
25 Pl_Concatenate::manualFinish() 30 Pl_Concatenate::manualFinish()
26 { 31 {
27 - getNext()->finish(); 32 + next()->finish();
28 } 33 }
libqpdf/Pl_Count.cc
@@ -2,9 +2,7 @@ @@ -2,9 +2,7 @@
2 2
3 #include <qpdf/QIntC.hh> 3 #include <qpdf/QIntC.hh>
4 4
5 -Pl_Count::Members::Members() :  
6 - count(0),  
7 - last_char('\0') 5 +Pl_Count::Members::Members()
8 { 6 {
9 } 7 }
10 8
@@ -12,6 +10,9 @@ Pl_Count::Pl_Count(char const* identifier, Pipeline* next) : @@ -12,6 +10,9 @@ Pl_Count::Pl_Count(char const* identifier, Pipeline* next) :
12 Pipeline(identifier, next), 10 Pipeline(identifier, next),
13 m(new Members()) 11 m(new Members())
14 { 12 {
  13 + if (!next) {
  14 + throw std::logic_error("Attempt to create Pl_Count with nullptr as next");
  15 + }
15 } 16 }
16 17
17 Pl_Count::~Pl_Count() // NOLINT (modernize-use-equals-default) 18 Pl_Count::~Pl_Count() // NOLINT (modernize-use-equals-default)
@@ -25,14 +26,14 @@ Pl_Count::write(unsigned char const* buf, size_t len) @@ -25,14 +26,14 @@ Pl_Count::write(unsigned char const* buf, size_t len)
25 if (len) { 26 if (len) {
26 m->count += QIntC::to_offset(len); 27 m->count += QIntC::to_offset(len);
27 m->last_char = buf[len - 1]; 28 m->last_char = buf[len - 1];
28 - getNext()->write(buf, len); 29 + next()->write(buf, len);
29 } 30 }
30 } 31 }
31 32
32 void 33 void
33 Pl_Count::finish() 34 Pl_Count::finish()
34 { 35 {
35 - getNext()->finish(); 36 + next()->finish();
36 } 37 }
37 38
38 qpdf_offset_t 39 qpdf_offset_t
libqpdf/Pl_DCT.cc
@@ -78,6 +78,9 @@ Pl_DCT::Pl_DCT(char const* identifier, Pipeline* next) : @@ -78,6 +78,9 @@ Pl_DCT::Pl_DCT(char const* identifier, Pipeline* next) :
78 Pipeline(identifier, next), 78 Pipeline(identifier, next),
79 m(new Members()) 79 m(new Members())
80 { 80 {
  81 + if (!next) {
  82 + throw std::logic_error("Attempt to create Pl_DCT with nullptr as next");
  83 + }
81 } 84 }
82 85
83 void 86 void
@@ -133,7 +136,7 @@ Pl_DCT::finish() @@ -133,7 +136,7 @@ Pl_DCT::finish()
133 // Special case: empty data will never succeed and probably means we're calling finish a 136 // Special case: empty data will never succeed and probably means we're calling finish a
134 // second time from an exception handler. 137 // second time from an exception handler.
135 delete b; 138 delete b;
136 - this->getNext()->finish(); 139 + next()->finish();
137 return; 140 return;
138 } 141 }
139 142
@@ -300,7 +303,7 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) @@ -300,7 +303,7 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b)
300 static int const BUF_SIZE = 65536; 303 static int const BUF_SIZE = 65536;
301 auto outbuffer_ph = std::make_unique<unsigned char[]>(BUF_SIZE); 304 auto outbuffer_ph = std::make_unique<unsigned char[]>(BUF_SIZE);
302 unsigned char* outbuffer = outbuffer_ph.get(); 305 unsigned char* outbuffer = outbuffer_ph.get();
303 - jpeg_pipeline_dest(cinfo, outbuffer, BUF_SIZE, this->getNext()); 306 + jpeg_pipeline_dest(cinfo, outbuffer, BUF_SIZE, next());
304 307
305 cinfo->image_width = m->image_width; 308 cinfo->image_width = m->image_width;
306 cinfo->image_height = m->image_height; 309 cinfo->image_height = m->image_height;
@@ -326,7 +329,7 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) @@ -326,7 +329,7 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b)
326 (void)jpeg_write_scanlines(cinfo, row_pointer, 1); 329 (void)jpeg_write_scanlines(cinfo, row_pointer, 1);
327 } 330 }
328 jpeg_finish_compress(cinfo); 331 jpeg_finish_compress(cinfo);
329 - this->getNext()->finish(); 332 + next()->finish();
330 } 333 }
331 334
332 void 335 void
@@ -370,8 +373,8 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b) @@ -370,8 +373,8 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b)
370 (void)jpeg_start_decompress(cinfo); 373 (void)jpeg_start_decompress(cinfo);
371 while (cinfo->output_scanline < cinfo->output_height) { 374 while (cinfo->output_scanline < cinfo->output_height) {
372 (void)jpeg_read_scanlines(cinfo, buffer, 1); 375 (void)jpeg_read_scanlines(cinfo, buffer, 1);
373 - getNext()->write(buffer[0], width * sizeof(buffer[0][0])); 376 + next()->write(buffer[0], width * sizeof(buffer[0][0]));
374 } 377 }
375 (void)jpeg_finish_decompress(cinfo); 378 (void)jpeg_finish_decompress(cinfo);
376 - getNext()->finish(); 379 + next()->finish();
377 } 380 }
libqpdf/Pl_Flate.cc
@@ -61,6 +61,9 @@ Pl_Flate::Pl_Flate( @@ -61,6 +61,9 @@ Pl_Flate::Pl_Flate(
61 Pipeline(identifier, next), 61 Pipeline(identifier, next),
62 m(new Members(QIntC::to_size(out_bufsize_int), action)) 62 m(new Members(QIntC::to_size(out_bufsize_int), action))
63 { 63 {
  64 + if (!next) {
  65 + throw std::logic_error("Attempt to create Pl_Flate with nullptr as next");
  66 + }
64 } 67 }
65 68
66 Pl_Flate::~Pl_Flate() // NOLINT (modernize-use-equals-default) 69 Pl_Flate::~Pl_Flate() // NOLINT (modernize-use-equals-default)
@@ -187,7 +190,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) @@ -187,7 +190,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
187 throw std::runtime_error("PL_Flate memory limit exceeded"); 190 throw std::runtime_error("PL_Flate memory limit exceeded");
188 } 191 }
189 } 192 }
190 - this->getNext()->write(m->outbuf.get(), ready); 193 + next()->write(m->outbuf.get(), ready);
191 zstream.next_out = m->outbuf.get(); 194 zstream.next_out = m->outbuf.get();
192 zstream.avail_out = QIntC::to_uint(m->out_bufsize); 195 zstream.avail_out = QIntC::to_uint(m->out_bufsize);
193 } 196 }
@@ -228,13 +231,13 @@ Pl_Flate::finish() @@ -228,13 +231,13 @@ Pl_Flate::finish()
228 } 231 }
229 } catch (std::exception& e) { 232 } catch (std::exception& e) {
230 try { 233 try {
231 - this->getNext()->finish(); 234 + next()->finish();
232 } catch (...) { 235 } catch (...) {
233 // ignore secondary exception 236 // ignore secondary exception
234 } 237 }
235 throw std::runtime_error(e.what()); 238 throw std::runtime_error(e.what());
236 } 239 }
237 - this->getNext()->finish(); 240 + next()->finish();
238 } 241 }
239 242
240 void 243 void
libqpdf/Pl_Function.cc
@@ -48,15 +48,15 @@ void @@ -48,15 +48,15 @@ void
48 Pl_Function::write(unsigned char const* buf, size_t len) 48 Pl_Function::write(unsigned char const* buf, size_t len)
49 { 49 {
50 m->fn(buf, len); 50 m->fn(buf, len);
51 - if (getNext(true)) {  
52 - getNext()->write(buf, len); 51 + if (next()) {
  52 + next()->write(buf, len);
53 } 53 }
54 } 54 }
55 55
56 void 56 void
57 Pl_Function::finish() 57 Pl_Function::finish()
58 { 58 {
59 - if (getNext(true)) {  
60 - getNext()->finish(); 59 + if (next()) {
  60 + next()->finish();
61 } 61 }
62 } 62 }
libqpdf/Pl_LZWDecoder.cc
@@ -8,25 +8,20 @@ @@ -8,25 +8,20 @@
8 8
9 Pl_LZWDecoder::Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change) : 9 Pl_LZWDecoder::Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change) :
10 Pipeline(identifier, next), 10 Pipeline(identifier, next),
11 - code_size(9),  
12 - next(0),  
13 - byte_pos(0),  
14 - bit_pos(0),  
15 - bits_available(0),  
16 - code_change_delta(early_code_change),  
17 - eod(false),  
18 - last_code(256) 11 + code_change_delta(early_code_change)
19 { 12 {
20 - memset(buf, 0, 3); 13 + if (!next) {
  14 + throw std::logic_error("Attempt to create Pl_LZWDecoder with nullptr as next");
  15 + }
21 } 16 }
22 17
23 void 18 void
24 Pl_LZWDecoder::write(unsigned char const* bytes, size_t len) 19 Pl_LZWDecoder::write(unsigned char const* bytes, size_t len)
25 { 20 {
26 for (size_t i = 0; i < len; ++i) { 21 for (size_t i = 0; i < len; ++i) {
27 - this->buf[next++] = bytes[i];  
28 - if (this->next == 3) {  
29 - this->next = 0; 22 + buf[next_char_++] = bytes[i];
  23 + if (next_char_ == 3) {
  24 + next_char_ = 0;
30 } 25 }
31 this->bits_available += 8; 26 this->bits_available += 8;
32 if (this->bits_available >= this->code_size) { 27 if (this->bits_available >= this->code_size) {
@@ -38,7 +33,7 @@ Pl_LZWDecoder::write(unsigned char const* bytes, size_t len) @@ -38,7 +33,7 @@ Pl_LZWDecoder::write(unsigned char const* bytes, size_t len)
38 void 33 void
39 Pl_LZWDecoder::finish() 34 Pl_LZWDecoder::finish()
40 { 35 {
41 - getNext()->finish(); 36 + next()->finish();
42 } 37 }
43 38
44 void 39 void
@@ -101,7 +96,7 @@ Pl_LZWDecoder::getFirstChar(unsigned int code) @@ -101,7 +96,7 @@ Pl_LZWDecoder::getFirstChar(unsigned int code)
101 } 96 }
102 97
103 void 98 void
104 -Pl_LZWDecoder::addToTable(unsigned char next) 99 +Pl_LZWDecoder::addToTable(unsigned char c)
105 { 100 {
106 unsigned int last_size = 0; 101 unsigned int last_size = 0;
107 unsigned char const* last_data = nullptr; 102 unsigned char const* last_data = nullptr;
@@ -128,7 +123,7 @@ Pl_LZWDecoder::addToTable(unsigned char next) @@ -128,7 +123,7 @@ Pl_LZWDecoder::addToTable(unsigned char next)
128 Buffer entry(1 + last_size); 123 Buffer entry(1 + last_size);
129 unsigned char* new_data = entry.getBuffer(); 124 unsigned char* new_data = entry.getBuffer();
130 memcpy(new_data, last_data, last_size); 125 memcpy(new_data, last_data, last_size);
131 - new_data[last_size] = next; 126 + new_data[last_size] = c;
132 this->table.push_back(std::move(entry)); 127 this->table.push_back(std::move(entry));
133 } 128 }
134 129
@@ -151,11 +146,11 @@ Pl_LZWDecoder::handleCode(unsigned int code) @@ -151,11 +146,11 @@ Pl_LZWDecoder::handleCode(unsigned int code)
151 if (this->last_code != 256) { 146 if (this->last_code != 256) {
152 // Add to the table from last time. New table entry would be what we read last plus the 147 // Add to the table from last time. New table entry would be what we read last plus the
153 // first character of what we're reading now. 148 // first character of what we're reading now.
154 - unsigned char next = ' = '\0';'; 149 + unsigned char next_c = ' = '\0';';
155 unsigned int table_size = QIntC::to_uint(table.size()); 150 unsigned int table_size = QIntC::to_uint(table.size());
156 if (code < 256) { 151 if (code < 256) {
157 - // just read < 256; last time's next was code  
158 - next = static_cast<unsigned char>(code); 152 + // just read < 256; last time's next_c was code
  153 + next_c = static_cast<unsigned char>(code);
159 } else if (code > 257) { 154 } else if (code > 257) {
160 size_t idx = code - 258; 155 size_t idx = code - 258;
161 if (idx > table_size) { 156 if (idx > table_size) {
@@ -164,16 +159,16 @@ Pl_LZWDecoder::handleCode(unsigned int code) @@ -164,16 +159,16 @@ Pl_LZWDecoder::handleCode(unsigned int code)
164 // The encoder would have just created this entry, so the first character of 159 // The encoder would have just created this entry, so the first character of
165 // this entry would have been the same as the first character of the last entry. 160 // this entry would have been the same as the first character of the last entry.
166 QTC::TC("libtests", "Pl_LZWDecoder last was table size"); 161 QTC::TC("libtests", "Pl_LZWDecoder last was table size");
167 - next = getFirstChar(this->last_code); 162 + next_c = getFirstChar(this->last_code);
168 } else { 163 } else {
169 - next = getFirstChar(code); 164 + next_c = getFirstChar(code);
170 } 165 }
171 } 166 }
172 unsigned int new_idx = 258 + table_size; 167 unsigned int new_idx = 258 + table_size;
173 if (new_idx == 4096) { 168 if (new_idx == 4096) {
174 throw std::runtime_error("LZWDecoder: table full"); 169 throw std::runtime_error("LZWDecoder: table full");
175 } 170 }
176 - addToTable(next); 171 + addToTable(next_c);
177 unsigned int change_idx = new_idx + code_change_delta; 172 unsigned int change_idx = new_idx + code_change_delta;
178 if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) { 173 if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) {
179 ++this->code_size; 174 ++this->code_size;
@@ -182,14 +177,14 @@ Pl_LZWDecoder::handleCode(unsigned int code) @@ -182,14 +177,14 @@ Pl_LZWDecoder::handleCode(unsigned int code)
182 177
183 if (code < 256) { 178 if (code < 256) {
184 auto ch = static_cast<unsigned char>(code); 179 auto ch = static_cast<unsigned char>(code);
185 - getNext()->write(&ch, 1); 180 + next()->write(&ch, 1);
186 } else { 181 } else {
187 unsigned int idx = code - 258; 182 unsigned int idx = code - 258;
188 if (idx >= table.size()) { 183 if (idx >= table.size()) {
189 throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow"); 184 throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow");
190 } 185 }
191 Buffer& b = table.at(idx); 186 Buffer& b = table.at(idx);
192 - getNext()->write(b.getBuffer(), b.getSize()); 187 + next()->write(b.getBuffer(), b.getSize());
193 } 188 }
194 } 189 }
195 190
libqpdf/Pl_MD5.cc
@@ -3,11 +3,11 @@ @@ -3,11 +3,11 @@
3 #include <stdexcept> 3 #include <stdexcept>
4 4
5 Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) : 5 Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) :
6 - Pipeline(identifier, next),  
7 - in_progress(false),  
8 - enabled(true),  
9 - persist_across_finish(false) 6 + Pipeline(identifier, next)
10 { 7 {
  8 + if (!next) {
  9 + throw std::logic_error("Attempt to create Pl_MD5 with nullptr as next");
  10 + }
11 } 11 }
12 12
13 void 13 void
@@ -31,13 +31,13 @@ Pl_MD5::write(unsigned char const* buf, size_t len) @@ -31,13 +31,13 @@ Pl_MD5::write(unsigned char const* buf, size_t len)
31 } 31 }
32 } 32 }
33 33
34 - this->getNext()->write(buf, len); 34 + next()->write(buf, len);
35 } 35 }
36 36
37 void 37 void
38 Pl_MD5::finish() 38 Pl_MD5::finish()
39 { 39 {
40 - this->getNext()->finish(); 40 + next()->finish();
41 if (!this->persist_across_finish) { 41 if (!this->persist_across_finish) {
42 this->in_progress = false; 42 this->in_progress = false;
43 } 43 }
libqpdf/Pl_PNGFilter.cc
@@ -26,13 +26,11 @@ Pl_PNGFilter::Pl_PNGFilter( @@ -26,13 +26,11 @@ Pl_PNGFilter::Pl_PNGFilter(
26 unsigned int samples_per_pixel, 26 unsigned int samples_per_pixel,
27 unsigned int bits_per_sample) : 27 unsigned int bits_per_sample) :
28 Pipeline(identifier, next), 28 Pipeline(identifier, next),
29 - action(action),  
30 - cur_row(nullptr),  
31 - prev_row(nullptr),  
32 - buf1(nullptr),  
33 - buf2(nullptr),  
34 - pos(0) 29 + action(action)
35 { 30 {
  31 + if (!next) {
  32 + throw std::logic_error("Attempt to create Pl_PNGFilter with nullptr as next");
  33 + }
36 if (samples_per_pixel < 1) { 34 if (samples_per_pixel < 1) {
37 throw std::runtime_error("PNGFilter created with invalid samples_per_pixel"); 35 throw std::runtime_error("PNGFilter created with invalid samples_per_pixel");
38 } 36 }
@@ -130,7 +128,7 @@ Pl_PNGFilter::decodeRow() @@ -130,7 +128,7 @@ Pl_PNGFilter::decodeRow()
130 } 128 }
131 } 129 }
132 130
133 - getNext()->write(this->cur_row + 1, this->bytes_per_row); 131 + next()->write(this->cur_row + 1, this->bytes_per_row);
134 } 132 }
135 133
136 void 134 void
@@ -230,14 +228,14 @@ Pl_PNGFilter::encodeRow() @@ -230,14 +228,14 @@ Pl_PNGFilter::encodeRow()
230 { 228 {
231 // For now, hard-code to using UP filter. 229 // For now, hard-code to using UP filter.
232 unsigned char ch = 2; 230 unsigned char ch = 2;
233 - getNext()->write(&ch, 1); 231 + next()->write(&ch, 1);
234 if (this->prev_row) { 232 if (this->prev_row) {
235 for (unsigned int i = 0; i < this->bytes_per_row; ++i) { 233 for (unsigned int i = 0; i < this->bytes_per_row; ++i) {
236 ch = static_cast<unsigned char>(this->cur_row[i] - this->prev_row[i]); 234 ch = static_cast<unsigned char>(this->cur_row[i] - this->prev_row[i]);
237 - getNext()->write(&ch, 1); 235 + next()->write(&ch, 1);
238 } 236 }
239 } else { 237 } else {
240 - getNext()->write(this->cur_row, this->bytes_per_row); 238 + next()->write(this->cur_row, this->bytes_per_row);
241 } 239 }
242 } 240 }
243 241
@@ -253,5 +251,5 @@ Pl_PNGFilter::finish() @@ -253,5 +251,5 @@ Pl_PNGFilter::finish()
253 this->pos = 0; 251 this->pos = 0;
254 memset(this->cur_row, 0, this->bytes_per_row + 1); 252 memset(this->cur_row, 0, this->bytes_per_row + 1);
255 253
256 - getNext()->finish(); 254 + next()->finish();
257 } 255 }
libqpdf/Pl_QPDFTokenizer.cc
@@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
5 #include <stdexcept> 5 #include <stdexcept>
6 6
7 Pl_QPDFTokenizer::Members::Members() : 7 Pl_QPDFTokenizer::Members::Members() :
8 - filter(nullptr),  
9 buf("tokenizer buffer") 8 buf("tokenizer buffer")
10 { 9 {
11 } 10 }
@@ -56,8 +55,7 @@ Pl_QPDFTokenizer::finish() @@ -56,8 +55,7 @@ Pl_QPDFTokenizer::finish()
56 } 55 }
57 m->filter->handleEOF(); 56 m->filter->handleEOF();
58 QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(m->filter, nullptr); 57 QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(m->filter, nullptr);
59 - Pipeline* next = this->getNext(true);  
60 - if (next) {  
61 - next->finish(); 58 + if (next()) {
  59 + next()->finish();
62 } 60 }
63 } 61 }
libqpdf/Pl_RC4.cc
@@ -12,6 +12,9 @@ Pl_RC4::Pl_RC4( @@ -12,6 +12,9 @@ Pl_RC4::Pl_RC4(
12 out_bufsize(out_bufsize), 12 out_bufsize(out_bufsize),
13 rc4(key_data, key_len) 13 rc4(key_data, key_len)
14 { 14 {
  15 + if (!next) {
  16 + throw std::logic_error("Attempt to create Pl_RC4 with nullptr as next");
  17 + }
15 this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize); 18 this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize);
16 } 19 }
17 20
@@ -31,13 +34,13 @@ Pl_RC4::write(unsigned char const* data, size_t len) @@ -31,13 +34,13 @@ Pl_RC4::write(unsigned char const* data, size_t len)
31 // lgtm[cpp/weak-cryptographic-algorithm] 34 // lgtm[cpp/weak-cryptographic-algorithm]
32 rc4.process(p, bytes, outbuf.get()); 35 rc4.process(p, bytes, outbuf.get());
33 p += bytes; 36 p += bytes;
34 - getNext()->write(outbuf.get(), bytes); 37 + next()->write(outbuf.get(), bytes);
35 } 38 }
36 } 39 }
37 40
38 void 41 void
39 Pl_RC4::finish() 42 Pl_RC4::finish()
40 { 43 {
41 - this->outbuf = nullptr;  
42 - this->getNext()->finish(); 44 + outbuf = nullptr;
  45 + next()->finish();
43 } 46 }
libqpdf/Pl_RunLength.cc
@@ -4,9 +4,7 @@ @@ -4,9 +4,7 @@
4 #include <qpdf/QUtil.hh> 4 #include <qpdf/QUtil.hh>
5 5
6 Pl_RunLength::Members::Members(action_e action) : 6 Pl_RunLength::Members::Members(action_e action) :
7 - action(action),  
8 - state(st_top),  
9 - length(0) 7 + action(action)
10 { 8 {
11 } 9 }
12 10
@@ -14,6 +12,9 @@ Pl_RunLength::Pl_RunLength(char const* identifier, Pipeline* next, action_e acti @@ -14,6 +12,9 @@ Pl_RunLength::Pl_RunLength(char const* identifier, Pipeline* next, action_e acti
14 Pipeline(identifier, next), 12 Pipeline(identifier, next),
15 m(new Members(action)) 13 m(new Members(action))
16 { 14 {
  15 + if (!next) {
  16 + throw std::logic_error("Attempt to create Pl_RunLength with nullptr as next");
  17 + }
17 } 18 }
18 19
19 Pl_RunLength::~Pl_RunLength() // NOLINT (modernize-use-equals-default) 20 Pl_RunLength::~Pl_RunLength() // NOLINT (modernize-use-equals-default)
@@ -119,12 +120,12 @@ Pl_RunLength::flush_encode() @@ -119,12 +120,12 @@ Pl_RunLength::flush_encode()
119 throw std::logic_error("Pl_RunLength: invalid length in flush_encode for run"); 120 throw std::logic_error("Pl_RunLength: invalid length in flush_encode for run");
120 } 121 }
121 auto ch = static_cast<unsigned char>(257 - m->length); 122 auto ch = static_cast<unsigned char>(257 - m->length);
122 - this->getNext()->write(&ch, 1);  
123 - this->getNext()->write(&m->buf[0], 1); 123 + next()->write(&ch, 1);
  124 + next()->write(&m->buf[0], 1);
124 } else if (m->length > 0) { 125 } else if (m->length > 0) {
125 auto ch = static_cast<unsigned char>(m->length - 1); 126 auto ch = static_cast<unsigned char>(m->length - 1);
126 - this->getNext()->write(&ch, 1);  
127 - this->getNext()->write(m->buf, m->length); 127 + next()->write(&ch, 1);
  128 + next()->write(m->buf, m->length);
128 } 129 }
129 m->state = st_top; 130 m->state = st_top;
130 m->length = 0; 131 m->length = 0;
@@ -136,13 +137,12 @@ Pl_RunLength::finish() @@ -136,13 +137,12 @@ Pl_RunLength::finish()
136 // When decoding, we might have read a length byte not followed by data, which means the stream 137 // When decoding, we might have read a length byte not followed by data, which means the stream
137 // was terminated early, but we will just ignore this case since this is the only sensible thing 138 // was terminated early, but we will just ignore this case since this is the only sensible thing
138 // to do. 139 // to do.
139 - auto next = getNext();  
140 if (m->action == a_encode) { 140 if (m->action == a_encode) {
141 flush_encode(); 141 flush_encode();
142 unsigned char ch = 128; 142 unsigned char ch = 128;
143 - next->write(&ch, 1); 143 + next()->write(&ch, 1);
144 } else { 144 } else {
145 - next->writeString(m->out); 145 + next()->writeString(m->out);
146 } 146 }
147 - next->finish(); 147 + next()->finish();
148 } 148 }
libqpdf/Pl_SHA2.cc
@@ -31,16 +31,16 @@ Pl_SHA2::write(unsigned char const* buf, size_t len) @@ -31,16 +31,16 @@ Pl_SHA2::write(unsigned char const* buf, size_t len)
31 data += bytes; 31 data += bytes;
32 } 32 }
33 33
34 - if (this->getNext(true)) {  
35 - this->getNext()->write(buf, len); 34 + if (next()) {
  35 + next()->write(buf, len);
36 } 36 }
37 } 37 }
38 38
39 void 39 void
40 Pl_SHA2::finish() 40 Pl_SHA2::finish()
41 { 41 {
42 - if (this->getNext(true)) {  
43 - this->getNext()->finish(); 42 + if (next()) {
  43 + next()->finish();
44 } 44 }
45 this->crypto->SHA2_finalize(); 45 this->crypto->SHA2_finalize();
46 this->in_progress = false; 46 this->in_progress = false;
libqpdf/Pl_String.cc
@@ -25,15 +25,15 @@ Pl_String::write(unsigned char const* buf, size_t len) @@ -25,15 +25,15 @@ Pl_String::write(unsigned char const* buf, size_t len)
25 return; 25 return;
26 } 26 }
27 m->s.append(reinterpret_cast<char const*>(buf), len); 27 m->s.append(reinterpret_cast<char const*>(buf), len);
28 - if (getNext(true)) {  
29 - getNext()->write(buf, len); 28 + if (next()) {
  29 + next()->write(buf, len);
30 } 30 }
31 } 31 }
32 32
33 void 33 void
34 Pl_String::finish() 34 Pl_String::finish()
35 { 35 {
36 - if (getNext(true)) {  
37 - getNext()->finish(); 36 + if (next()) {
  37 + next()->finish();
38 } 38 }
39 } 39 }
libqpdf/Pl_TIFFPredictor.cc
@@ -23,9 +23,11 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( @@ -23,9 +23,11 @@ Pl_TIFFPredictor::Pl_TIFFPredictor(
23 action(action), 23 action(action),
24 columns(columns), 24 columns(columns),
25 samples_per_pixel(samples_per_pixel), 25 samples_per_pixel(samples_per_pixel),
26 - bits_per_sample(bits_per_sample),  
27 - p_next(getNext()) 26 + bits_per_sample(bits_per_sample)
28 { 27 {
  28 + if (!next) {
  29 + throw std::logic_error("Attempt to create Pl_TIFFPredictor with nullptr as next");
  30 + }
29 if (samples_per_pixel < 1) { 31 if (samples_per_pixel < 1) {
30 throw std::runtime_error("TIFFPredictor created with invalid samples_per_pixel"); 32 throw std::runtime_error("TIFFPredictor created with invalid samples_per_pixel");
31 } 33 }
@@ -74,7 +76,7 @@ Pl_TIFFPredictor::processRow() @@ -74,7 +76,7 @@ Pl_TIFFPredictor::processRow()
74 QTC::TC("libtests", "Pl_TIFFPredictor processRow", (action == a_decode ? 0 : 1)); 76 QTC::TC("libtests", "Pl_TIFFPredictor processRow", (action == a_decode ? 0 : 1));
75 previous.assign(samples_per_pixel, 0); 77 previous.assign(samples_per_pixel, 0);
76 if (bits_per_sample != 8) { 78 if (bits_per_sample != 8) {
77 - BitWriter bw(p_next); 79 + BitWriter bw(next());
78 BitStream in(cur_row.data(), cur_row.size()); 80 BitStream in(cur_row.data(), cur_row.size());
79 for (unsigned int col = 0; col < this->columns; ++col) { 81 for (unsigned int col = 0; col < this->columns; ++col) {
80 for (auto& prev: previous) { 82 for (auto& prev: previous) {
@@ -93,13 +95,14 @@ Pl_TIFFPredictor::processRow() @@ -93,13 +95,14 @@ Pl_TIFFPredictor::processRow()
93 bw.flush(); 95 bw.flush();
94 } else { 96 } else {
95 out.clear(); 97 out.clear();
96 - auto next = cur_row.begin(); 98 + auto next_it = cur_row.begin();
97 auto cr_end = cur_row.end(); 99 auto cr_end = cur_row.end();
98 auto pr_end = previous.end(); 100 auto pr_end = previous.end();
99 101
100 - while (next != cr_end) {  
101 - for (auto prev = previous.begin(); prev != pr_end && next != cr_end; ++prev, ++next) {  
102 - long long sample = *next; 102 + while (next_it != cr_end) {
  103 + for (auto prev = previous.begin(); prev != pr_end && next_it != cr_end;
  104 + ++prev, ++next_it) {
  105 + long long sample = *next_it;
103 long long new_sample = sample; 106 long long new_sample = sample;
104 if (action == a_encode) { 107 if (action == a_encode) {
105 new_sample -= *prev; 108 new_sample -= *prev;
@@ -111,7 +114,7 @@ Pl_TIFFPredictor::processRow() @@ -111,7 +114,7 @@ Pl_TIFFPredictor::processRow()
111 out.push_back(static_cast<unsigned char>(255U & new_sample)); 114 out.push_back(static_cast<unsigned char>(255U & new_sample));
112 } 115 }
113 } 116 }
114 - p_next->write(out.data(), out.size()); 117 + next()->write(out.data(), out.size());
115 } 118 }
116 } 119 }
117 120
@@ -124,5 +127,5 @@ Pl_TIFFPredictor::finish() @@ -124,5 +127,5 @@ Pl_TIFFPredictor::finish()
124 processRow(); 127 processRow();
125 } 128 }
126 cur_row.clear(); 129 cur_row.clear();
127 - p_next->finish(); 130 + next()->finish();
128 } 131 }
libqpdf/QPDFLogger.cc
@@ -14,19 +14,22 @@ namespace @@ -14,19 +14,22 @@ namespace
14 Pl_Track(char const* identifier, Pipeline* next) : 14 Pl_Track(char const* identifier, Pipeline* next) :
15 Pipeline(identifier, next) 15 Pipeline(identifier, next)
16 { 16 {
  17 + if (!next) {
  18 + throw std::logic_error("Attempt to create Pl_Track with nullptr as next");
  19 + }
17 } 20 }
18 21
19 void 22 void
20 - write(unsigned char const* data, size_t len) override 23 + write(unsigned char const* data, size_t len) final
21 { 24 {
22 - this->used = true;  
23 - getNext()->write(data, len); 25 + used = true;
  26 + next()->write(data, len);
24 } 27 }
25 28
26 void 29 void
27 - finish() override 30 + finish() final
28 { 31 {
29 - getNext()->finish(); 32 + next()->finish();
30 } 33 }
31 34
32 bool 35 bool
libqpdf/QPDFObjectHandle.cc
@@ -181,13 +181,13 @@ QPDFObjectHandle::ParserCallbacks::terminateParsing() @@ -181,13 +181,13 @@ QPDFObjectHandle::ParserCallbacks::terminateParsing()
181 181
182 namespace 182 namespace
183 { 183 {
184 - class LastChar: public Pipeline 184 + class LastChar final: public Pipeline
185 { 185 {
186 public: 186 public:
187 - LastChar(Pipeline* next);  
188 - ~LastChar() override = default;  
189 - void write(unsigned char const* data, size_t len) override;  
190 - void finish() override; 187 + LastChar(Pipeline& next);
  188 + ~LastChar() final = default;
  189 + void write(unsigned char const* data, size_t len) final;
  190 + void finish() final;
191 unsigned char getLastChar(); 191 unsigned char getLastChar();
192 192
193 private: 193 private:
@@ -195,8 +195,8 @@ namespace @@ -195,8 +195,8 @@ namespace
195 }; 195 };
196 } // namespace 196 } // namespace
197 197
198 -LastChar::LastChar(Pipeline* next) :  
199 - Pipeline("lastchar", next) 198 +LastChar::LastChar(Pipeline& next) :
  199 + Pipeline("lastchar", &next)
200 { 200 {
201 } 201 }
202 202
@@ -206,13 +206,13 @@ LastChar::write(unsigned char const* data, size_t len) @@ -206,13 +206,13 @@ LastChar::write(unsigned char const* data, size_t len)
206 if (len > 0) { 206 if (len > 0) {
207 this->last_char = data[len - 1]; 207 this->last_char = data[len - 1];
208 } 208 }
209 - getNext()->write(data, len); 209 + next()->write(data, len);
210 } 210 }
211 211
212 void 212 void
213 LastChar::finish() 213 LastChar::finish()
214 { 214 {
215 - getNext()->finish(); 215 + next()->finish();
216 } 216 }
217 217
218 unsigned char 218 unsigned char
@@ -2073,7 +2073,7 @@ QPDFObjectHandle::pipeContentStreams( @@ -2073,7 +2073,7 @@ QPDFObjectHandle::pipeContentStreams(
2073 if (need_newline) { 2073 if (need_newline) {
2074 buf.writeCStr("\n"); 2074 buf.writeCStr("\n");
2075 } 2075 }
2076 - LastChar lc(&buf); 2076 + LastChar lc(buf);
2077 if (!stream.pipeStreamData(&lc, 0, qpdf_dl_specialized)) { 2077 if (!stream.pipeStreamData(&lc, 0, qpdf_dl_specialized)) {
2078 QTC::TC("qpdf", "QPDFObjectHandle errors in parsecontent"); 2078 QTC::TC("qpdf", "QPDFObjectHandle errors in parsecontent");
2079 throw QPDFExc( 2079 throw QPDFExc(
libqpdf/qpdf/Pl_AES_PDF.hh
@@ -7,8 +7,7 @@ @@ -7,8 +7,7 @@
7 7
8 // This pipeline implements AES-128 and AES-256 with CBC and block padding as specified in the PDF 8 // This pipeline implements AES-128 and AES-256 with CBC and block padding as specified in the PDF
9 // specification. 9 // specification.
10 -  
11 -class Pl_AES_PDF: public Pipeline 10 +class Pl_AES_PDF final: public Pipeline
12 { 11 {
13 public: 12 public:
14 // key should be a pointer to key_bytes bytes of data 13 // key should be a pointer to key_bytes bytes of data
@@ -18,10 +17,10 @@ class Pl_AES_PDF: public Pipeline @@ -18,10 +17,10 @@ class Pl_AES_PDF: public Pipeline
18 bool encrypt, 17 bool encrypt,
19 unsigned char const* key, 18 unsigned char const* key,
20 size_t key_bytes); 19 size_t key_bytes);
21 - ~Pl_AES_PDF() override = default; 20 + ~Pl_AES_PDF() final = default;
22 21
23 - void write(unsigned char const* data, size_t len) override;  
24 - void finish() override; 22 + void write(unsigned char const* data, size_t len) final;
  23 + void finish() final;
25 24
26 // Use zero initialization vector; needed for AESV3 25 // Use zero initialization vector; needed for AESV3
27 void useZeroIV(); 26 void useZeroIV();
@@ -45,18 +44,18 @@ class Pl_AES_PDF: public Pipeline @@ -45,18 +44,18 @@ class Pl_AES_PDF: public Pipeline
45 44
46 std::shared_ptr<QPDFCryptoImpl> crypto; 45 std::shared_ptr<QPDFCryptoImpl> crypto;
47 bool encrypt; 46 bool encrypt;
48 - bool cbc_mode;  
49 - bool first;  
50 - size_t offset; // offset into memory buffer 47 + bool cbc_mode{true};
  48 + bool first{true};
  49 + size_t offset{0}; // offset into memory buffer
51 std::unique_ptr<unsigned char[]> key; 50 std::unique_ptr<unsigned char[]> key;
52 - size_t key_bytes; 51 + size_t key_bytes{0};
53 unsigned char inbuf[buf_size]; 52 unsigned char inbuf[buf_size];
54 unsigned char outbuf[buf_size]; 53 unsigned char outbuf[buf_size];
55 unsigned char cbc_block[buf_size]; 54 unsigned char cbc_block[buf_size];
56 unsigned char specified_iv[buf_size]; 55 unsigned char specified_iv[buf_size];
57 - bool use_zero_iv;  
58 - bool use_specified_iv;  
59 - bool disable_padding; 56 + bool use_zero_iv{false};
  57 + bool use_specified_iv{false};
  58 + bool disable_padding{false};
60 }; 59 };
61 60
62 #endif // PL_AES_PDF_HH 61 #endif // PL_AES_PDF_HH
libqpdf/qpdf/Pl_ASCII85Decoder.hh
@@ -3,20 +3,20 @@ @@ -3,20 +3,20 @@
3 3
4 #include <qpdf/Pipeline.hh> 4 #include <qpdf/Pipeline.hh>
5 5
6 -class Pl_ASCII85Decoder: public Pipeline 6 +class Pl_ASCII85Decoder final: public Pipeline
7 { 7 {
8 public: 8 public:
9 Pl_ASCII85Decoder(char const* identifier, Pipeline* next); 9 Pl_ASCII85Decoder(char const* identifier, Pipeline* next);
10 - ~Pl_ASCII85Decoder() override = default;  
11 - void write(unsigned char const* buf, size_t len) override;  
12 - void finish() override; 10 + ~Pl_ASCII85Decoder() final = default;
  11 + void write(unsigned char const* buf, size_t len) final;
  12 + void finish() final;
13 13
14 private: 14 private:
15 void flush(); 15 void flush();
16 16
17 - unsigned char inbuf[5];  
18 - size_t pos;  
19 - size_t eod; 17 + unsigned char inbuf[5]{117, 117, 117, 117, 117};
  18 + size_t pos{0};
  19 + size_t eod{0};
20 }; 20 };
21 21
22 #endif // PL_ASCII85DECODER_HH 22 #endif // PL_ASCII85DECODER_HH
libqpdf/qpdf/Pl_ASCIIHexDecoder.hh
@@ -3,20 +3,20 @@ @@ -3,20 +3,20 @@
3 3
4 #include <qpdf/Pipeline.hh> 4 #include <qpdf/Pipeline.hh>
5 5
6 -class Pl_ASCIIHexDecoder: public Pipeline 6 +class Pl_ASCIIHexDecoder final: public Pipeline
7 { 7 {
8 public: 8 public:
9 Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next); 9 Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next);
10 - ~Pl_ASCIIHexDecoder() override = default;  
11 - void write(unsigned char const* buf, size_t len) override;  
12 - void finish() override; 10 + ~Pl_ASCIIHexDecoder() final = default;
  11 + void write(unsigned char const* buf, size_t len) final;
  12 + void finish() final;
13 13
14 private: 14 private:
15 void flush(); 15 void flush();
16 16
17 - char inbuf[3];  
18 - size_t pos;  
19 - bool eod; 17 + char inbuf[3]{'0', '0', '\0'};
  18 + size_t pos{0};
  19 + bool eod{false};
20 }; 20 };
21 21
22 #endif // PL_ASCIIHEXDECODER_HH 22 #endif // PL_ASCIIHEXDECODER_HH
libqpdf/qpdf/Pl_Base64.hh
@@ -3,14 +3,14 @@ @@ -3,14 +3,14 @@
3 3
4 #include <qpdf/Pipeline.hh> 4 #include <qpdf/Pipeline.hh>
5 5
6 -class Pl_Base64: public Pipeline 6 +class Pl_Base64 final: public Pipeline
7 { 7 {
8 public: 8 public:
9 enum action_e { a_encode, a_decode }; 9 enum action_e { a_encode, a_decode };
10 Pl_Base64(char const* identifier, Pipeline* next, action_e); 10 Pl_Base64(char const* identifier, Pipeline* next, action_e);
11 - ~Pl_Base64() override = default;  
12 - void write(unsigned char const* buf, size_t len) override;  
13 - void finish() override; 11 + ~Pl_Base64() final = default;
  12 + void write(unsigned char const* buf, size_t len) final;
  13 + void finish() final;
14 14
15 private: 15 private:
16 void decode(unsigned char const* buf, size_t len); 16 void decode(unsigned char const* buf, size_t len);
@@ -21,10 +21,10 @@ class Pl_Base64: public Pipeline @@ -21,10 +21,10 @@ class Pl_Base64: public Pipeline
21 void reset(); 21 void reset();
22 22
23 action_e action; 23 action_e action;
24 - unsigned char buf[4];  
25 - size_t pos;  
26 - bool end_of_data;  
27 - bool finished; 24 + unsigned char buf[4]{0, 0, 0, 0};
  25 + size_t pos{0};
  26 + bool end_of_data{false};
  27 + bool finished{false};
28 }; 28 };
29 29
30 #endif // PL_BASE64_HH 30 #endif // PL_BASE64_HH
libqpdf/qpdf/Pl_LZWDecoder.hh
@@ -6,13 +6,13 @@ @@ -6,13 +6,13 @@
6 #include <qpdf/Buffer.hh> 6 #include <qpdf/Buffer.hh>
7 #include <vector> 7 #include <vector>
8 8
9 -class Pl_LZWDecoder: public Pipeline 9 +class Pl_LZWDecoder final: public Pipeline
10 { 10 {
11 public: 11 public:
12 Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change); 12 Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change);
13 - ~Pl_LZWDecoder() override = default;  
14 - void write(unsigned char const* buf, size_t len) override;  
15 - void finish() override; 13 + ~Pl_LZWDecoder() final = default;
  14 + void write(unsigned char const* buf, size_t len) final;
  15 + void finish() final;
16 16
17 private: 17 private:
18 void sendNextCode(); 18 void sendNextCode();
@@ -21,18 +21,18 @@ class Pl_LZWDecoder: public Pipeline @@ -21,18 +21,18 @@ class Pl_LZWDecoder: public Pipeline
21 void addToTable(unsigned char next); 21 void addToTable(unsigned char next);
22 22
23 // members used for converting bits to codes 23 // members used for converting bits to codes
24 - unsigned char buf[3];  
25 - unsigned int code_size;  
26 - unsigned int next;  
27 - unsigned int byte_pos;  
28 - unsigned int bit_pos; // left to right: 01234567  
29 - unsigned int bits_available; 24 + unsigned char buf[3]{0, 0, 0};
  25 + unsigned int code_size{9};
  26 + unsigned int next_char_{0};
  27 + unsigned int byte_pos{0};
  28 + unsigned int bit_pos{0}; // left to right: 01234567
  29 + unsigned int bits_available{0};
30 30
31 // members used for handle LZW decompression 31 // members used for handle LZW decompression
32 - bool code_change_delta;  
33 - bool eod; 32 + bool code_change_delta{false};
  33 + bool eod{false};
34 std::vector<Buffer> table; 34 std::vector<Buffer> table;
35 - unsigned int last_code; 35 + unsigned int last_code{256};
36 }; 36 };
37 37
38 #endif // PL_LZWDECODER_HH 38 #endif // PL_LZWDECODER_HH
libqpdf/qpdf/Pl_MD5.hh
1 #ifndef PL_MD5_HH 1 #ifndef PL_MD5_HH
2 #define PL_MD5_HH 2 #define PL_MD5_HH
3 3
  4 +#include <qpdf/MD5.hh>
  5 +#include <qpdf/Pipeline.hh>
  6 +
4 // This pipeline sends its output to its successor unmodified. After calling finish, the MD5 7 // This pipeline sends its output to its successor unmodified. After calling finish, the MD5
5 // checksum of the data that passed through the pipeline is available. 8 // checksum of the data that passed through the pipeline is available.
6 9
7 // This pipeline is reusable; i.e., it is safe to call write() after calling finish(). The first 10 // This pipeline is reusable; i.e., it is safe to call write() after calling finish(). The first
8 // call to write() after a call to finish() initializes a new MD5 object. 11 // call to write() after a call to finish() initializes a new MD5 object.
9 -  
10 -#include <qpdf/MD5.hh>  
11 -#include <qpdf/Pipeline.hh>  
12 -  
13 -class Pl_MD5: public Pipeline 12 +class Pl_MD5 final: public Pipeline
14 { 13 {
15 public: 14 public:
16 Pl_MD5(char const* identifier, Pipeline* next); 15 Pl_MD5(char const* identifier, Pipeline* next);
17 - ~Pl_MD5() override = default;  
18 - void write(unsigned char const*, size_t) override;  
19 - void finish() override; 16 + ~Pl_MD5() final = default;
  17 + void write(unsigned char const*, size_t) final;
  18 + void finish() final;
20 std::string getHexDigest(); 19 std::string getHexDigest();
21 // Enable/disable. Disabling the pipeline causes it to become a pass-through. This makes it 20 // Enable/disable. Disabling the pipeline causes it to become a pass-through. This makes it
22 // possible to stick an MD5 pipeline in a pipeline when it may or may not be required. Disabling 21 // possible to stick an MD5 pipeline in a pipeline when it may or may not be required. Disabling
@@ -27,10 +26,10 @@ class Pl_MD5: public Pipeline @@ -27,10 +26,10 @@ class Pl_MD5: public Pipeline
27 void persistAcrossFinish(bool); 26 void persistAcrossFinish(bool);
28 27
29 private: 28 private:
30 - bool in_progress; 29 + bool in_progress{false};
31 MD5 md5; 30 MD5 md5;
32 - bool enabled;  
33 - bool persist_across_finish; 31 + bool enabled{true};
  32 + bool persist_across_finish{false};
34 }; 33 };
35 34
36 #endif // PL_MD5_HH 35 #endif // PL_MD5_HH
libqpdf/qpdf/Pl_PNGFilter.hh
1 #ifndef PL_PNGFILTER_HH 1 #ifndef PL_PNGFILTER_HH
2 #define PL_PNGFILTER_HH 2 #define PL_PNGFILTER_HH
3 3
  4 +#include <qpdf/Pipeline.hh>
  5 +
4 // This pipeline applies or reverses the application of a PNG filter as described in the PNG 6 // This pipeline applies or reverses the application of a PNG filter as described in the PNG
5 // specification. 7 // specification.
6 - 8 +//
7 // NOTE: In its current implementation, this filter always encodes using the "up" filter, but it 9 // NOTE: In its current implementation, this filter always encodes using the "up" filter, but it
8 // decodes all the filters. 10 // decodes all the filters.
9 -  
10 -#include <qpdf/Pipeline.hh>  
11 -  
12 -class Pl_PNGFilter: public Pipeline 11 +class Pl_PNGFilter final: public Pipeline
13 { 12 {
14 public: 13 public:
15 // Encoding is only partially supported 14 // Encoding is only partially supported
@@ -22,14 +21,14 @@ class Pl_PNGFilter: public Pipeline @@ -22,14 +21,14 @@ class Pl_PNGFilter: public Pipeline
22 unsigned int columns, 21 unsigned int columns,
23 unsigned int samples_per_pixel = 1, 22 unsigned int samples_per_pixel = 1,
24 unsigned int bits_per_sample = 8); 23 unsigned int bits_per_sample = 8);
25 - ~Pl_PNGFilter() override = default; 24 + ~Pl_PNGFilter() final = default;
26 25
27 // Limit the memory used. 26 // Limit the memory used.
28 // NB This is a static option affecting all Pl_PNGFilter instances. 27 // NB This is a static option affecting all Pl_PNGFilter instances.
29 static void setMemoryLimit(unsigned long long limit); 28 static void setMemoryLimit(unsigned long long limit);
30 29
31 - void write(unsigned char const* data, size_t len) override;  
32 - void finish() override; 30 + void write(unsigned char const* data, size_t len) final;
  31 + void finish() final;
33 32
34 private: 33 private:
35 void decodeSub(); 34 void decodeSub();
@@ -44,12 +43,12 @@ class Pl_PNGFilter: public Pipeline @@ -44,12 +43,12 @@ class Pl_PNGFilter: public Pipeline
44 action_e action; 43 action_e action;
45 unsigned int bytes_per_row; 44 unsigned int bytes_per_row;
46 unsigned int bytes_per_pixel; 45 unsigned int bytes_per_pixel;
47 - unsigned char* cur_row; // points to buf1 or buf2  
48 - unsigned char* prev_row; // points to buf1 or buf2 46 + unsigned char* cur_row{nullptr}; // points to buf1 or buf2
  47 + unsigned char* prev_row{nullptr}; // points to buf1 or buf2
49 std::shared_ptr<unsigned char> buf1; 48 std::shared_ptr<unsigned char> buf1;
50 std::shared_ptr<unsigned char> buf2; 49 std::shared_ptr<unsigned char> buf2;
51 - size_t pos;  
52 - size_t incoming; 50 + size_t pos{0};
  51 + size_t incoming{0};
53 }; 52 };
54 53
55 #endif // PL_PNGFILTER_HH 54 #endif // PL_PNGFILTER_HH
libqpdf/qpdf/Pl_RC4.hh
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 5
6 #include <qpdf/RC4.hh> 6 #include <qpdf/RC4.hh>
7 7
8 -class Pl_RC4: public Pipeline 8 +class Pl_RC4 final: public Pipeline
9 { 9 {
10 public: 10 public:
11 static size_t const def_bufsize = 65536; 11 static size_t const def_bufsize = 65536;
@@ -17,10 +17,10 @@ class Pl_RC4: public Pipeline @@ -17,10 +17,10 @@ class Pl_RC4: public Pipeline
17 unsigned char const* key_data, 17 unsigned char const* key_data,
18 int key_len = -1, 18 int key_len = -1,
19 size_t out_bufsize = def_bufsize); 19 size_t out_bufsize = def_bufsize);
20 - ~Pl_RC4() override = default; 20 + ~Pl_RC4() final = default;
21 21
22 - void write(unsigned char const* data, size_t len) override;  
23 - void finish() override; 22 + void write(unsigned char const* data, size_t len) final;
  23 + void finish() final;
24 24
25 private: 25 private:
26 std::shared_ptr<unsigned char> outbuf; 26 std::shared_ptr<unsigned char> outbuf;
libqpdf/qpdf/Pl_SHA2.hh
1 #ifndef PL_SHA2_HH 1 #ifndef PL_SHA2_HH
2 #define PL_SHA2_HH 2 #define PL_SHA2_HH
3 3
  4 +#include <qpdf/Pipeline.hh>
  5 +#include <qpdf/QPDFCryptoImpl.hh>
  6 +#include <memory>
  7 +
4 // Bits must be a supported number of bits, currently only 256, 384, or 512. Passing 0 as bits 8 // Bits must be a supported number of bits, currently only 256, 384, or 512. Passing 0 as bits
5 // leaves the pipeline uncommitted, in which case resetBits must be called before the pipeline is 9 // leaves the pipeline uncommitted, in which case resetBits must be called before the pipeline is
6 // used. If a next is provided, this pipeline sends its output to its successor unmodified. After 10 // used. If a next is provided, this pipeline sends its output to its successor unmodified. After
7 // calling finish, the SHA2 checksum of the data that passed through the pipeline is available. 11 // calling finish, the SHA2 checksum of the data that passed through the pipeline is available.
8 - 12 +//
9 // This pipeline is reusable; i.e., it is safe to call write() after calling finish(). The first 13 // This pipeline is reusable; i.e., it is safe to call write() after calling finish(). The first
10 // call to write() after a call to finish() initializes a new SHA2 object. resetBits may also be 14 // call to write() after a call to finish() initializes a new SHA2 object. resetBits may also be
11 // called between finish and the next call to write. 15 // called between finish and the next call to write.
12 -  
13 -#include <qpdf/Pipeline.hh>  
14 -#include <qpdf/QPDFCryptoImpl.hh>  
15 -#include <memory>  
16 -  
17 -class Pl_SHA2: public Pipeline 16 +class Pl_SHA2 final: public Pipeline
18 { 17 {
19 public: 18 public:
20 Pl_SHA2(int bits = 0, Pipeline* next = nullptr); 19 Pl_SHA2(int bits = 0, Pipeline* next = nullptr);
21 - ~Pl_SHA2() override = default;  
22 - void write(unsigned char const*, size_t) override;  
23 - void finish() override; 20 + ~Pl_SHA2() final = default;
  21 + void write(unsigned char const*, size_t) final;
  22 + void finish() final;
24 void resetBits(int bits); 23 void resetBits(int bits);
25 std::string getHexDigest(); 24 std::string getHexDigest();
26 std::string getRawDigest(); 25 std::string getRawDigest();
libqpdf/qpdf/Pl_TIFFPredictor.hh
@@ -40,7 +40,6 @@ class Pl_TIFFPredictor: public Pipeline @@ -40,7 +40,6 @@ class Pl_TIFFPredictor: public Pipeline
40 std::vector<unsigned char> cur_row; 40 std::vector<unsigned char> cur_row;
41 std::vector<long long> previous; 41 std::vector<long long> previous;
42 std::vector<unsigned char> out; 42 std::vector<unsigned char> out;
43 - Pipeline* p_next;  
44 }; 43 };
45 44
46 #endif // PL_TIFFPREDICTOR_HH 45 #endif // PL_TIFFPREDICTOR_HH