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