Commit 34f52682f5e9500e1fa28dec98a986fd67610310
Committed by
GitHub
Merge pull request #1485 from m-holger/modern
Miscellaneous code modernisation
Showing
21 changed files
with
396 additions
and
445 deletions
libqpdf/AES_PDF_native.cc
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | 11 | ||
| 12 | AES_PDF_native::AES_PDF_native( | 12 | AES_PDF_native::AES_PDF_native( |
| 13 | bool encrypt, | 13 | bool encrypt, |
| 14 | - unsigned char const* key, | 14 | + unsigned char const* a_key, |
| 15 | size_t key_bytes, | 15 | size_t key_bytes, |
| 16 | bool cbc_mode, | 16 | bool cbc_mode, |
| 17 | unsigned char* cbc_block) : | 17 | unsigned char* cbc_block) : |
| @@ -20,38 +20,38 @@ AES_PDF_native::AES_PDF_native( | @@ -20,38 +20,38 @@ AES_PDF_native::AES_PDF_native( | ||
| 20 | cbc_block(cbc_block) | 20 | cbc_block(cbc_block) |
| 21 | { | 21 | { |
| 22 | size_t keybits = 8 * key_bytes; | 22 | size_t keybits = 8 * key_bytes; |
| 23 | - this->key = std::make_unique<unsigned char[]>(key_bytes); | ||
| 24 | - this->rk = std::make_unique<uint32_t[]>(RKLENGTH(keybits)); | 23 | + key = std::make_unique<unsigned char[]>(key_bytes); |
| 24 | + rk = std::make_unique<uint32_t[]>(RKLENGTH(keybits)); | ||
| 25 | size_t rk_bytes = RKLENGTH(keybits) * sizeof(uint32_t); | 25 | size_t rk_bytes = RKLENGTH(keybits) * sizeof(uint32_t); |
| 26 | - std::memcpy(this->key.get(), key, key_bytes); | ||
| 27 | - std::memset(this->rk.get(), 0, rk_bytes); | 26 | + std::memcpy(key.get(), a_key, key_bytes); |
| 27 | + std::memset(rk.get(), 0, rk_bytes); | ||
| 28 | if (encrypt) { | 28 | if (encrypt) { |
| 29 | - this->nrounds = rijndaelSetupEncrypt(this->rk.get(), this->key.get(), keybits); | 29 | + nrounds = rijndaelSetupEncrypt(rk.get(), key.get(), keybits); |
| 30 | } else { | 30 | } else { |
| 31 | - this->nrounds = rijndaelSetupDecrypt(this->rk.get(), this->key.get(), keybits); | 31 | + nrounds = rijndaelSetupDecrypt(rk.get(), key.get(), keybits); |
| 32 | } | 32 | } |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | void | 35 | void |
| 36 | AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data) | 36 | AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data) |
| 37 | { | 37 | { |
| 38 | - if (this->encrypt) { | ||
| 39 | - if (this->cbc_mode) { | 38 | + if (encrypt) { |
| 39 | + if (cbc_mode) { | ||
| 40 | for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i) { | 40 | for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i) { |
| 41 | - in_data[i] ^= this->cbc_block[i]; | 41 | + in_data[i] ^= cbc_block[i]; |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
| 44 | - rijndaelEncrypt(this->rk.get(), this->nrounds, in_data, out_data); | ||
| 45 | - if (this->cbc_mode) { | ||
| 46 | - memcpy(this->cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size); | 44 | + rijndaelEncrypt(rk.get(), nrounds, in_data, out_data); |
| 45 | + if (cbc_mode) { | ||
| 46 | + memcpy(cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size); | ||
| 47 | } | 47 | } |
| 48 | } else { | 48 | } else { |
| 49 | - rijndaelDecrypt(this->rk.get(), this->nrounds, in_data, out_data); | ||
| 50 | - if (this->cbc_mode) { | 49 | + rijndaelDecrypt(rk.get(), nrounds, in_data, out_data); |
| 50 | + if (cbc_mode) { | ||
| 51 | for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i) { | 51 | for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i) { |
| 52 | - out_data[i] ^= this->cbc_block[i]; | 52 | + out_data[i] ^= cbc_block[i]; |
| 53 | } | 53 | } |
| 54 | - memcpy(this->cbc_block, in_data, QPDFCryptoImpl::rijndael_buf_size); | 54 | + memcpy(cbc_block, in_data, QPDFCryptoImpl::rijndael_buf_size); |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
libqpdf/BufferInputSource.cc
| @@ -26,42 +26,42 @@ BufferInputSource::BufferInputSource(std::string const& description, std::string | @@ -26,42 +26,42 @@ BufferInputSource::BufferInputSource(std::string const& description, std::string | ||
| 26 | 26 | ||
| 27 | BufferInputSource::~BufferInputSource() | 27 | BufferInputSource::~BufferInputSource() |
| 28 | { | 28 | { |
| 29 | - if (this->own_memory) { | ||
| 30 | - delete this->buf; | 29 | + if (own_memory) { |
| 30 | + delete buf; | ||
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | qpdf_offset_t | 34 | qpdf_offset_t |
| 35 | BufferInputSource::findAndSkipNextEOL() | 35 | BufferInputSource::findAndSkipNextEOL() |
| 36 | { | 36 | { |
| 37 | - if (this->cur_offset < 0) { | 37 | + if (cur_offset < 0) { |
| 38 | throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); | 38 | throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); |
| 39 | } | 39 | } |
| 40 | - qpdf_offset_t end_pos = this->max_offset; | ||
| 41 | - if (this->cur_offset >= end_pos) { | ||
| 42 | - this->last_offset = end_pos; | ||
| 43 | - this->cur_offset = end_pos; | 40 | + qpdf_offset_t end_pos = max_offset; |
| 41 | + if (cur_offset >= end_pos) { | ||
| 42 | + last_offset = end_pos; | ||
| 43 | + cur_offset = end_pos; | ||
| 44 | return end_pos; | 44 | return end_pos; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | qpdf_offset_t result = 0; | 47 | qpdf_offset_t result = 0; |
| 48 | - unsigned char const* buffer = this->buf->getBuffer(); | 48 | + unsigned char const* buffer = buf->getBuffer(); |
| 49 | unsigned char const* end = buffer + end_pos; | 49 | unsigned char const* end = buffer + end_pos; |
| 50 | - unsigned char const* p = buffer + this->cur_offset; | 50 | + unsigned char const* p = buffer + cur_offset; |
| 51 | 51 | ||
| 52 | while ((p < end) && !((*p == '\r') || (*p == '\n'))) { | 52 | while ((p < end) && !((*p == '\r') || (*p == '\n'))) { |
| 53 | ++p; | 53 | ++p; |
| 54 | } | 54 | } |
| 55 | if (p < end) { | 55 | if (p < end) { |
| 56 | result = p - buffer; | 56 | result = p - buffer; |
| 57 | - this->cur_offset = result + 1; | 57 | + cur_offset = result + 1; |
| 58 | ++p; | 58 | ++p; |
| 59 | - while ((this->cur_offset < end_pos) && ((*p == '\r') || (*p == '\n'))) { | 59 | + while ((cur_offset < end_pos) && ((*p == '\r') || (*p == '\n'))) { |
| 60 | ++p; | 60 | ++p; |
| 61 | - ++this->cur_offset; | 61 | + ++cur_offset; |
| 62 | } | 62 | } |
| 63 | } else { | 63 | } else { |
| 64 | - this->cur_offset = end_pos; | 64 | + cur_offset = end_pos; |
| 65 | result = end_pos; | 65 | result = end_pos; |
| 66 | } | 66 | } |
| 67 | return result; | 67 | return result; |
| @@ -70,13 +70,13 @@ BufferInputSource::findAndSkipNextEOL() | @@ -70,13 +70,13 @@ BufferInputSource::findAndSkipNextEOL() | ||
| 70 | std::string const& | 70 | std::string const& |
| 71 | BufferInputSource::getName() const | 71 | BufferInputSource::getName() const |
| 72 | { | 72 | { |
| 73 | - return this->description; | 73 | + return description; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | qpdf_offset_t | 76 | qpdf_offset_t |
| 77 | BufferInputSource::tell() | 77 | BufferInputSource::tell() |
| 78 | { | 78 | { |
| 79 | - return this->cur_offset; | 79 | + return cur_offset; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | void | 82 | void |
| @@ -84,17 +84,17 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) | @@ -84,17 +84,17 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) | ||
| 84 | { | 84 | { |
| 85 | switch (whence) { | 85 | switch (whence) { |
| 86 | case SEEK_SET: | 86 | case SEEK_SET: |
| 87 | - this->cur_offset = offset; | 87 | + cur_offset = offset; |
| 88 | break; | 88 | break; |
| 89 | 89 | ||
| 90 | case SEEK_END: | 90 | case SEEK_END: |
| 91 | - QIntC::range_check(this->max_offset, offset); | ||
| 92 | - this->cur_offset = this->max_offset + offset; | 91 | + QIntC::range_check(max_offset, offset); |
| 92 | + cur_offset = max_offset + offset; | ||
| 93 | break; | 93 | break; |
| 94 | 94 | ||
| 95 | case SEEK_CUR: | 95 | case SEEK_CUR: |
| 96 | - QIntC::range_check(this->cur_offset, offset); | ||
| 97 | - this->cur_offset += offset; | 96 | + QIntC::range_check(cur_offset, offset); |
| 97 | + cur_offset += offset; | ||
| 98 | break; | 98 | break; |
| 99 | 99 | ||
| 100 | default: | 100 | default: |
| @@ -102,40 +102,40 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) | @@ -102,40 +102,40 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) | ||
| 102 | break; | 102 | break; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | - if (this->cur_offset < 0) { | ||
| 106 | - throw std::runtime_error(this->description + ": seek before beginning of buffer"); | 105 | + if (cur_offset < 0) { |
| 106 | + throw std::runtime_error(description + ": seek before beginning of buffer"); | ||
| 107 | } | 107 | } |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | void | 110 | void |
| 111 | BufferInputSource::rewind() | 111 | BufferInputSource::rewind() |
| 112 | { | 112 | { |
| 113 | - this->cur_offset = 0; | 113 | + cur_offset = 0; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | size_t | 116 | size_t |
| 117 | BufferInputSource::read(char* buffer, size_t length) | 117 | BufferInputSource::read(char* buffer, size_t length) |
| 118 | { | 118 | { |
| 119 | - if (this->cur_offset < 0) { | 119 | + if (cur_offset < 0) { |
| 120 | throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); | 120 | throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); |
| 121 | } | 121 | } |
| 122 | - qpdf_offset_t end_pos = this->max_offset; | ||
| 123 | - if (this->cur_offset >= end_pos) { | ||
| 124 | - this->last_offset = end_pos; | 122 | + qpdf_offset_t end_pos = max_offset; |
| 123 | + if (cur_offset >= end_pos) { | ||
| 124 | + last_offset = end_pos; | ||
| 125 | return 0; | 125 | return 0; |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | - this->last_offset = this->cur_offset; | ||
| 129 | - size_t len = std::min(QIntC::to_size(end_pos - this->cur_offset), length); | ||
| 130 | - memcpy(buffer, this->buf->getBuffer() + this->cur_offset, len); | ||
| 131 | - this->cur_offset += QIntC::to_offset(len); | 128 | + last_offset = cur_offset; |
| 129 | + size_t len = std::min(QIntC::to_size(end_pos - cur_offset), length); | ||
| 130 | + memcpy(buffer, buf->getBuffer() + cur_offset, len); | ||
| 131 | + cur_offset += QIntC::to_offset(len); | ||
| 132 | return len; | 132 | return len; |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | void | 135 | void |
| 136 | BufferInputSource::unreadCh(char ch) | 136 | BufferInputSource::unreadCh(char ch) |
| 137 | { | 137 | { |
| 138 | - if (this->cur_offset > 0) { | ||
| 139 | - --this->cur_offset; | 138 | + if (cur_offset > 0) { |
| 139 | + --cur_offset; | ||
| 140 | } | 140 | } |
| 141 | } | 141 | } |
libqpdf/MD5.cc
| @@ -14,14 +14,14 @@ MD5::MD5() | @@ -14,14 +14,14 @@ MD5::MD5() | ||
| 14 | void | 14 | void |
| 15 | MD5::init() | 15 | MD5::init() |
| 16 | { | 16 | { |
| 17 | - this->crypto = QPDFCryptoProvider::getImpl(); | ||
| 18 | - this->crypto->MD5_init(); | 17 | + crypto = QPDFCryptoProvider::getImpl(); |
| 18 | + crypto->MD5_init(); | ||
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | void | 21 | void |
| 22 | MD5::finalize() | 22 | MD5::finalize() |
| 23 | { | 23 | { |
| 24 | - this->crypto->MD5_finalize(); | 24 | + crypto->MD5_finalize(); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | void | 27 | void |
| @@ -48,7 +48,7 @@ MD5::appendString(char const* input_string) | @@ -48,7 +48,7 @@ MD5::appendString(char const* input_string) | ||
| 48 | void | 48 | void |
| 49 | MD5::encodeDataIncrementally(char const* data, size_t len) | 49 | MD5::encodeDataIncrementally(char const* data, size_t len) |
| 50 | { | 50 | { |
| 51 | - this->crypto->MD5_update(QUtil::unsigned_char_pointer(data), len); | 51 | + crypto->MD5_update(QUtil::unsigned_char_pointer(data), len); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | void | 54 | void |
| @@ -84,14 +84,14 @@ MD5::encodeFile(char const* filename, qpdf_offset_t up_to_offset) | @@ -84,14 +84,14 @@ MD5::encodeFile(char const* filename, qpdf_offset_t up_to_offset) | ||
| 84 | } | 84 | } |
| 85 | (void)fclose(file); | 85 | (void)fclose(file); |
| 86 | 86 | ||
| 87 | - this->crypto->MD5_finalize(); | 87 | + crypto->MD5_finalize(); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | void | 90 | void |
| 91 | MD5::digest(Digest result) | 91 | MD5::digest(Digest result) |
| 92 | { | 92 | { |
| 93 | - this->crypto->MD5_finalize(); | ||
| 94 | - this->crypto->MD5_digest(result); | 93 | + crypto->MD5_finalize(); |
| 94 | + crypto->MD5_digest(result); | ||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | void | 97 | void |
| @@ -110,7 +110,7 @@ MD5::print() | @@ -110,7 +110,7 @@ MD5::print() | ||
| 110 | std::string | 110 | std::string |
| 111 | MD5::unparse() | 111 | MD5::unparse() |
| 112 | { | 112 | { |
| 113 | - this->crypto->MD5_finalize(); | 113 | + crypto->MD5_finalize(); |
| 114 | Digest digest_val; | 114 | Digest digest_val; |
| 115 | digest(digest_val); | 115 | digest(digest_val); |
| 116 | return QUtil::hex_encode(std::string(reinterpret_cast<char*>(digest_val), 16)); | 116 | return QUtil::hex_encode(std::string(reinterpret_cast<char*>(digest_val), 16)); |
libqpdf/NNTree.cc
| @@ -49,12 +49,12 @@ NNTreeIterator::updateIValue(bool allow_invalid) | @@ -49,12 +49,12 @@ NNTreeIterator::updateIValue(bool allow_invalid) | ||
| 49 | // call updateIValue in operator* and operator->. | 49 | // call updateIValue in operator* and operator->. |
| 50 | 50 | ||
| 51 | bool okay = false; | 51 | bool okay = false; |
| 52 | - if ((item_number >= 0) && this->node.isDictionary()) { | ||
| 53 | - auto items = this->node.getKey(impl.details.itemsKey()); | ||
| 54 | - if (this->item_number + 1 < items.getArrayNItems()) { | 52 | + if (item_number >= 0 && node.isDictionary()) { |
| 53 | + auto items = node.getKey(impl.details.itemsKey()); | ||
| 54 | + if (item_number + 1 < items.getArrayNItems()) { | ||
| 55 | okay = true; | 55 | okay = true; |
| 56 | - this->ivalue.first = items.getArrayItem(this->item_number); | ||
| 57 | - this->ivalue.second = items.getArrayItem(1 + this->item_number); | 56 | + ivalue.first = items.getArrayItem(item_number); |
| 57 | + ivalue.second = items.getArrayItem(1 + item_number); | ||
| 58 | } else { | 58 | } else { |
| 59 | error(impl.qpdf, node, "update ivalue: items array is too short"); | 59 | error(impl.qpdf, node, "update ivalue: items array is too short"); |
| 60 | } | 60 | } |
| @@ -64,8 +64,8 @@ NNTreeIterator::updateIValue(bool allow_invalid) | @@ -64,8 +64,8 @@ NNTreeIterator::updateIValue(bool allow_invalid) | ||
| 64 | throw std::logic_error( | 64 | throw std::logic_error( |
| 65 | "attempt made to dereference an invalid name/number tree iterator"); | 65 | "attempt made to dereference an invalid name/number tree iterator"); |
| 66 | } | 66 | } |
| 67 | - this->ivalue.first = QPDFObjectHandle(); | ||
| 68 | - this->ivalue.second = QPDFObjectHandle(); | 67 | + ivalue.first = QPDFObjectHandle(); |
| 68 | + ivalue.second = QPDFObjectHandle(); | ||
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| 71 | 71 | ||
| @@ -106,45 +106,45 @@ NNTreeIterator::getNextKid(PathElement& pe, bool backward) | @@ -106,45 +106,45 @@ NNTreeIterator::getNextKid(PathElement& pe, bool backward) | ||
| 106 | bool | 106 | bool |
| 107 | NNTreeIterator::valid() const | 107 | NNTreeIterator::valid() const |
| 108 | { | 108 | { |
| 109 | - return this->item_number >= 0; | 109 | + return item_number >= 0; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | void | 112 | void |
| 113 | NNTreeIterator::increment(bool backward) | 113 | NNTreeIterator::increment(bool backward) |
| 114 | { | 114 | { |
| 115 | - if (this->item_number < 0) { | 115 | + if (item_number < 0) { |
| 116 | QTC::TC("qpdf", "NNTree increment end()"); | 116 | QTC::TC("qpdf", "NNTree increment end()"); |
| 117 | deepen(impl.oh, !backward, true); | 117 | deepen(impl.oh, !backward, true); |
| 118 | return; | 118 | return; |
| 119 | } | 119 | } |
| 120 | bool found_valid_key = false; | 120 | bool found_valid_key = false; |
| 121 | - while (valid() && (!found_valid_key)) { | ||
| 122 | - this->item_number += backward ? -2 : 2; | ||
| 123 | - auto items = this->node.getKey(impl.details.itemsKey()); | ||
| 124 | - if ((this->item_number < 0) || (this->item_number >= items.getArrayNItems())) { | 121 | + while (valid() && !found_valid_key) { |
| 122 | + item_number += backward ? -2 : 2; | ||
| 123 | + auto items = node.getKey(impl.details.itemsKey()); | ||
| 124 | + if (item_number < 0 || item_number >= items.getArrayNItems()) { | ||
| 125 | bool found = false; | 125 | bool found = false; |
| 126 | setItemNumber(QPDFObjectHandle(), -1); | 126 | setItemNumber(QPDFObjectHandle(), -1); |
| 127 | - while (!(found || this->path.empty())) { | ||
| 128 | - auto& element = this->path.back(); | 127 | + while (!(found || path.empty())) { |
| 128 | + auto& element = path.back(); | ||
| 129 | auto pe_node = getNextKid(element, backward); | 129 | auto pe_node = getNextKid(element, backward); |
| 130 | if (pe_node.isNull()) { | 130 | if (pe_node.isNull()) { |
| 131 | - this->path.pop_back(); | 131 | + path.pop_back(); |
| 132 | } else { | 132 | } else { |
| 133 | found = deepen(pe_node, !backward, false); | 133 | found = deepen(pe_node, !backward, false); |
| 134 | } | 134 | } |
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | - if (this->item_number >= 0) { | ||
| 138 | - items = this->node.getKey(impl.details.itemsKey()); | ||
| 139 | - if (this->item_number + 1 >= items.getArrayNItems()) { | 137 | + if (item_number >= 0) { |
| 138 | + items = node.getKey(impl.details.itemsKey()); | ||
| 139 | + if (item_number + 1 >= items.getArrayNItems()) { | ||
| 140 | QTC::TC("qpdf", "NNTree skip item at end of short items"); | 140 | QTC::TC("qpdf", "NNTree skip item at end of short items"); |
| 141 | - warn(impl.qpdf, this->node, "items array doesn't have enough elements"); | ||
| 142 | - } else if (!impl.details.keyValid(items.getArrayItem(this->item_number))) { | 141 | + warn(impl.qpdf, node, "items array doesn't have enough elements"); |
| 142 | + } else if (!impl.details.keyValid(items.getArrayItem(item_number))) { | ||
| 143 | QTC::TC("qpdf", "NNTree skip invalid key"); | 143 | QTC::TC("qpdf", "NNTree skip invalid key"); |
| 144 | warn( | 144 | warn( |
| 145 | impl.qpdf, | 145 | impl.qpdf, |
| 146 | - this->node, | ||
| 147 | - ("item " + std::to_string(this->item_number) + " has the wrong type")); | 146 | + node, |
| 147 | + ("item " + std::to_string(item_number) + " has the wrong type")); | ||
| 148 | } else { | 148 | } else { |
| 149 | found_valid_key = true; | 149 | found_valid_key = true; |
| 150 | } | 150 | } |
| @@ -153,19 +153,19 @@ NNTreeIterator::increment(bool backward) | @@ -153,19 +153,19 @@ NNTreeIterator::increment(bool backward) | ||
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | void | 155 | void |
| 156 | -NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::iterator parent) | 156 | +NNTreeIterator::resetLimits(QPDFObjectHandle a_node, std::list<PathElement>::iterator parent) |
| 157 | { | 157 | { |
| 158 | bool done = false; | 158 | bool done = false; |
| 159 | while (!done) { | 159 | while (!done) { |
| 160 | - if (parent == this->path.end()) { | 160 | + if (parent == path.end()) { |
| 161 | QTC::TC("qpdf", "NNTree remove limits from root"); | 161 | QTC::TC("qpdf", "NNTree remove limits from root"); |
| 162 | - node.removeKey("/Limits"); | 162 | + a_node.removeKey("/Limits"); |
| 163 | done = true; | 163 | done = true; |
| 164 | break; | 164 | break; |
| 165 | } | 165 | } |
| 166 | - auto kids = node.getKey("/Kids"); | 166 | + auto kids = a_node.getKey("/Kids"); |
| 167 | int nkids = kids.isArray() ? kids.getArrayNItems() : 0; | 167 | int nkids = kids.isArray() ? kids.getArrayNItems() : 0; |
| 168 | - auto items = node.getKey(impl.details.itemsKey()); | 168 | + auto items = a_node.getKey(impl.details.itemsKey()); |
| 169 | int nitems = items.isArray() ? items.getArrayNItems() : 0; | 169 | int nitems = items.isArray() ? items.getArrayNItems() : 0; |
| 170 | 170 | ||
| 171 | bool changed = true; | 171 | bool changed = true; |
| @@ -191,7 +191,7 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::itera | @@ -191,7 +191,7 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::itera | ||
| 191 | auto limits = QPDFObjectHandle::newArray(); | 191 | auto limits = QPDFObjectHandle::newArray(); |
| 192 | limits.appendItem(first); | 192 | limits.appendItem(first); |
| 193 | limits.appendItem(last); | 193 | limits.appendItem(last); |
| 194 | - auto olimits = node.getKey("/Limits"); | 194 | + auto olimits = a_node.getKey("/Limits"); |
| 195 | if (olimits.isArray() && (olimits.getArrayNItems() == 2)) { | 195 | if (olimits.isArray() && (olimits.getArrayNItems() == 2)) { |
| 196 | auto ofirst = olimits.getArrayItem(0); | 196 | auto ofirst = olimits.getArrayItem(0); |
| 197 | auto olast = olimits.getArrayItem(1); | 197 | auto olast = olimits.getArrayItem(1); |
| @@ -202,18 +202,18 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::itera | @@ -202,18 +202,18 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::itera | ||
| 202 | changed = false; | 202 | changed = false; |
| 203 | } | 203 | } |
| 204 | } | 204 | } |
| 205 | - if (changed && !node.isSameObjectAs(path.begin()->node)) { | ||
| 206 | - node.replaceKey("/Limits", limits); | 205 | + if (changed && !a_node.isSameObjectAs(path.begin()->node)) { |
| 206 | + a_node.replaceKey("/Limits", limits); | ||
| 207 | } | 207 | } |
| 208 | } else { | 208 | } else { |
| 209 | QTC::TC("qpdf", "NNTree unable to determine limits"); | 209 | QTC::TC("qpdf", "NNTree unable to determine limits"); |
| 210 | - warn(impl.qpdf, node, "unable to determine limits"); | 210 | + warn(impl.qpdf, a_node, "unable to determine limits"); |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | - if ((!changed) || (parent == this->path.begin())) { | 213 | + if (!changed || parent == path.begin()) { |
| 214 | done = true; | 214 | done = true; |
| 215 | } else { | 215 | } else { |
| 216 | - node = parent->node; | 216 | + a_node = parent->node; |
| 217 | --parent; | 217 | --parent; |
| 218 | } | 218 | } |
| 219 | } | 219 | } |
| @@ -283,7 +283,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato | @@ -283,7 +283,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato | ||
| 283 | return; | 283 | return; |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | - bool is_root = (parent == this->path.end()); | 286 | + bool is_root = (parent == path.end()); |
| 287 | bool is_leaf = (nitems > 0); | 287 | bool is_leaf = (nitems > 0); |
| 288 | 288 | ||
| 289 | // CURRENT STATE: tree is in original state; iterator is valid and unchanged. | 289 | // CURRENT STATE: tree is in original state; iterator is valid and unchanged. |
| @@ -312,14 +312,14 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato | @@ -312,14 +312,14 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato | ||
| 312 | to_split.replaceKey("/Kids", new_kids); | 312 | to_split.replaceKey("/Kids", new_kids); |
| 313 | if (is_leaf) { | 313 | if (is_leaf) { |
| 314 | QTC::TC("qpdf", "NNTree split root + leaf"); | 314 | QTC::TC("qpdf", "NNTree split root + leaf"); |
| 315 | - this->node = first_node; | 315 | + node = first_node; |
| 316 | } else { | 316 | } else { |
| 317 | QTC::TC("qpdf", "NNTree split root + !leaf"); | 317 | QTC::TC("qpdf", "NNTree split root + !leaf"); |
| 318 | - auto next = this->path.begin(); | 318 | + auto next = path.begin(); |
| 319 | next->node = first_node; | 319 | next->node = first_node; |
| 320 | } | 320 | } |
| 321 | this->path.emplace_front(to_split, 0); | 321 | this->path.emplace_front(to_split, 0); |
| 322 | - parent = this->path.begin(); | 322 | + parent = path.begin(); |
| 323 | to_split = first_node; | 323 | to_split = first_node; |
| 324 | } | 324 | } |
| 325 | 325 | ||
| @@ -353,12 +353,12 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato | @@ -353,12 +353,12 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato | ||
| 353 | parent_kids.insertItem(parent->kid_number + 1, second_node); | 353 | parent_kids.insertItem(parent->kid_number + 1, second_node); |
| 354 | auto cur_elem = parent; | 354 | auto cur_elem = parent; |
| 355 | ++cur_elem; // points to end() for leaf nodes | 355 | ++cur_elem; // points to end() for leaf nodes |
| 356 | - int old_idx = (is_leaf ? this->item_number : cur_elem->kid_number); | 356 | + int old_idx = (is_leaf ? item_number : cur_elem->kid_number); |
| 357 | if (old_idx >= start_idx) { | 357 | if (old_idx >= start_idx) { |
| 358 | ++parent->kid_number; | 358 | ++parent->kid_number; |
| 359 | if (is_leaf) { | 359 | if (is_leaf) { |
| 360 | QTC::TC("qpdf", "NNTree split second half item"); | 360 | QTC::TC("qpdf", "NNTree split second half item"); |
| 361 | - setItemNumber(second_node, this->item_number - start_idx); | 361 | + setItemNumber(second_node, item_number - start_idx); |
| 362 | } else { | 362 | } else { |
| 363 | QTC::TC("qpdf", "NNTree split second half kid"); | 363 | QTC::TC("qpdf", "NNTree split second half kid"); |
| 364 | cur_elem->node = second_node; | 364 | cur_elem->node = second_node; |
| @@ -377,8 +377,8 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato | @@ -377,8 +377,8 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato | ||
| 377 | std::list<NNTreeIterator::PathElement>::iterator | 377 | std::list<NNTreeIterator::PathElement>::iterator |
| 378 | NNTreeIterator::lastPathElement() | 378 | NNTreeIterator::lastPathElement() |
| 379 | { | 379 | { |
| 380 | - auto result = this->path.end(); | ||
| 381 | - if (!this->path.empty()) { | 380 | + auto result = path.end(); |
| 381 | + if (!path.empty()) { | ||
| 382 | --result; | 382 | --result; |
| 383 | } | 383 | } |
| 384 | return result; | 384 | return result; |
| @@ -394,17 +394,17 @@ NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value) | @@ -394,17 +394,17 @@ NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value) | ||
| 394 | return; | 394 | return; |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | - auto items = this->node.getKey(impl.details.itemsKey()); | 397 | + auto items = node.getKey(impl.details.itemsKey()); |
| 398 | if (!items.isArray()) { | 398 | if (!items.isArray()) { |
| 399 | error(impl.qpdf, node, "node contains no items array"); | 399 | error(impl.qpdf, node, "node contains no items array"); |
| 400 | } | 400 | } |
| 401 | - if (items.getArrayNItems() < this->item_number + 2) { | 401 | + if (items.getArrayNItems() < item_number + 2) { |
| 402 | error(impl.qpdf, node, "insert: items array is too short"); | 402 | error(impl.qpdf, node, "insert: items array is too short"); |
| 403 | } | 403 | } |
| 404 | - items.insertItem(this->item_number + 2, key); | ||
| 405 | - items.insertItem(this->item_number + 3, value); | ||
| 406 | - resetLimits(this->node, lastPathElement()); | ||
| 407 | - split(this->node, lastPathElement()); | 404 | + items.insertItem(item_number + 2, key); |
| 405 | + items.insertItem(item_number + 3, value); | ||
| 406 | + resetLimits(node, lastPathElement()); | ||
| 407 | + split(node, lastPathElement()); | ||
| 408 | increment(false); | 408 | increment(false); |
| 409 | } | 409 | } |
| 410 | 410 | ||
| @@ -416,33 +416,33 @@ NNTreeIterator::remove() | @@ -416,33 +416,33 @@ NNTreeIterator::remove() | ||
| 416 | if (!valid()) { | 416 | if (!valid()) { |
| 417 | throw std::logic_error("attempt made to remove an invalid iterator"); | 417 | throw std::logic_error("attempt made to remove an invalid iterator"); |
| 418 | } | 418 | } |
| 419 | - auto items = this->node.getKey(impl.details.itemsKey()); | 419 | + auto items = node.getKey(impl.details.itemsKey()); |
| 420 | int nitems = items.getArrayNItems(); | 420 | int nitems = items.getArrayNItems(); |
| 421 | - if (this->item_number + 2 > nitems) { | ||
| 422 | - error(impl.qpdf, this->node, "found short items array while removing an item"); | 421 | + if (item_number + 2 > nitems) { |
| 422 | + error(impl.qpdf, node, "found short items array while removing an item"); | ||
| 423 | } | 423 | } |
| 424 | 424 | ||
| 425 | - items.eraseItem(this->item_number); | ||
| 426 | - items.eraseItem(this->item_number); | 425 | + items.eraseItem(item_number); |
| 426 | + items.eraseItem(item_number); | ||
| 427 | nitems -= 2; | 427 | nitems -= 2; |
| 428 | 428 | ||
| 429 | if (nitems > 0) { | 429 | if (nitems > 0) { |
| 430 | // There are still items left | 430 | // There are still items left |
| 431 | 431 | ||
| 432 | - if ((this->item_number == 0) || (this->item_number == nitems)) { | 432 | + if (item_number == 0 || item_number == nitems) { |
| 433 | // We removed either the first or last item of an items array that remains non-empty, so | 433 | // We removed either the first or last item of an items array that remains non-empty, so |
| 434 | // we have to adjust limits. | 434 | // we have to adjust limits. |
| 435 | QTC::TC("qpdf", "NNTree remove reset limits"); | 435 | QTC::TC("qpdf", "NNTree remove reset limits"); |
| 436 | - resetLimits(this->node, lastPathElement()); | 436 | + resetLimits(node, lastPathElement()); |
| 437 | } | 437 | } |
| 438 | 438 | ||
| 439 | - if (this->item_number == nitems) { | 439 | + if (item_number == nitems) { |
| 440 | // We removed the last item of a non-empty items array, so advance to the successor of | 440 | // We removed the last item of a non-empty items array, so advance to the successor of |
| 441 | // the previous item. | 441 | // the previous item. |
| 442 | QTC::TC("qpdf", "NNTree erased last item"); | 442 | QTC::TC("qpdf", "NNTree erased last item"); |
| 443 | - this->item_number -= 2; | 443 | + item_number -= 2; |
| 444 | increment(false); | 444 | increment(false); |
| 445 | - } else if (this->item_number < nitems) { | 445 | + } else if (item_number < nitems) { |
| 446 | // We don't have to do anything since the removed item's successor now occupies its | 446 | // We don't have to do anything since the removed item's successor now occupies its |
| 447 | // former location. | 447 | // former location. |
| 448 | QTC::TC("qpdf", "NNTree erased non-last item"); | 448 | QTC::TC("qpdf", "NNTree erased non-last item"); |
| @@ -454,7 +454,7 @@ NNTreeIterator::remove() | @@ -454,7 +454,7 @@ NNTreeIterator::remove() | ||
| 454 | return; | 454 | return; |
| 455 | } | 455 | } |
| 456 | 456 | ||
| 457 | - if (this->path.empty()) { | 457 | + if (path.empty()) { |
| 458 | // Special case: if this is the root node, we can leave it empty. | 458 | // Special case: if this is the root node, we can leave it empty. |
| 459 | QTC::TC("qpdf", "NNTree erased all items on leaf/root"); | 459 | QTC::TC("qpdf", "NNTree erased all items on leaf/root"); |
| 460 | setItemNumber(impl.oh, -1); | 460 | setItemNumber(impl.oh, -1); |
| @@ -498,18 +498,18 @@ NNTreeIterator::remove() | @@ -498,18 +498,18 @@ NNTreeIterator::remove() | ||
| 498 | deepen(kids.getArrayItem(element->kid_number), true, true); | 498 | deepen(kids.getArrayItem(element->kid_number), true, true); |
| 499 | } | 499 | } |
| 500 | done = true; | 500 | done = true; |
| 501 | - } else if (parent == this->path.end()) { | 501 | + } else if (parent == path.end()) { |
| 502 | // We erased the very last item. Convert the root to an empty items array. | 502 | // We erased the very last item. Convert the root to an empty items array. |
| 503 | QTC::TC("qpdf", "NNTree non-flat tree is empty after remove"); | 503 | QTC::TC("qpdf", "NNTree non-flat tree is empty after remove"); |
| 504 | element->node.removeKey("/Kids"); | 504 | element->node.removeKey("/Kids"); |
| 505 | element->node.replaceKey(impl.details.itemsKey(), QPDFObjectHandle::newArray()); | 505 | element->node.replaceKey(impl.details.itemsKey(), QPDFObjectHandle::newArray()); |
| 506 | - this->path.clear(); | 506 | + path.clear(); |
| 507 | setItemNumber(impl.oh, -1); | 507 | setItemNumber(impl.oh, -1); |
| 508 | done = true; | 508 | done = true; |
| 509 | } else { | 509 | } else { |
| 510 | // Walk up the tree and continue | 510 | // Walk up the tree and continue |
| 511 | QTC::TC("qpdf", "NNTree remove walking up tree"); | 511 | QTC::TC("qpdf", "NNTree remove walking up tree"); |
| 512 | - this->path.pop_back(); | 512 | + path.pop_back(); |
| 513 | } | 513 | } |
| 514 | } | 514 | } |
| 515 | } | 515 | } |
| @@ -532,99 +532,99 @@ NNTreeIterator::reference | @@ -532,99 +532,99 @@ NNTreeIterator::reference | ||
| 532 | NNTreeIterator::operator*() | 532 | NNTreeIterator::operator*() |
| 533 | { | 533 | { |
| 534 | updateIValue(false); | 534 | updateIValue(false); |
| 535 | - return this->ivalue; | 535 | + return ivalue; |
| 536 | } | 536 | } |
| 537 | 537 | ||
| 538 | NNTreeIterator::pointer | 538 | NNTreeIterator::pointer |
| 539 | NNTreeIterator::operator->() | 539 | NNTreeIterator::operator->() |
| 540 | { | 540 | { |
| 541 | updateIValue(false); | 541 | updateIValue(false); |
| 542 | - return &(this->ivalue); | 542 | + return &ivalue; |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | bool | 545 | bool |
| 546 | NNTreeIterator::operator==(NNTreeIterator const& other) const | 546 | NNTreeIterator::operator==(NNTreeIterator const& other) const |
| 547 | { | 547 | { |
| 548 | - if ((this->item_number == -1) && (other.item_number == -1)) { | 548 | + if (item_number == -1 && other.item_number == -1) { |
| 549 | return true; | 549 | return true; |
| 550 | } | 550 | } |
| 551 | - if (this->path.size() != other.path.size()) { | 551 | + if (path.size() != other.path.size()) { |
| 552 | return false; | 552 | return false; |
| 553 | } | 553 | } |
| 554 | - auto tpi = this->path.begin(); | 554 | + auto tpi = path.begin(); |
| 555 | auto opi = other.path.begin(); | 555 | auto opi = other.path.begin(); |
| 556 | - while (tpi != this->path.end()) { | 556 | + while (tpi != path.end()) { |
| 557 | if (tpi->kid_number != opi->kid_number) { | 557 | if (tpi->kid_number != opi->kid_number) { |
| 558 | return false; | 558 | return false; |
| 559 | } | 559 | } |
| 560 | ++tpi; | 560 | ++tpi; |
| 561 | ++opi; | 561 | ++opi; |
| 562 | } | 562 | } |
| 563 | - if (this->item_number != other.item_number) { | 563 | + if (item_number != other.item_number) { |
| 564 | return false; | 564 | return false; |
| 565 | } | 565 | } |
| 566 | return true; | 566 | return true; |
| 567 | } | 567 | } |
| 568 | 568 | ||
| 569 | void | 569 | void |
| 570 | -NNTreeIterator::setItemNumber(QPDFObjectHandle const& node, int n) | 570 | +NNTreeIterator::setItemNumber(QPDFObjectHandle const& a_node, int n) |
| 571 | { | 571 | { |
| 572 | - this->node = node; | ||
| 573 | - this->item_number = n; | 572 | + node = a_node; |
| 573 | + item_number = n; | ||
| 574 | updateIValue(); | 574 | updateIValue(); |
| 575 | } | 575 | } |
| 576 | 576 | ||
| 577 | void | 577 | void |
| 578 | -NNTreeIterator::addPathElement(QPDFObjectHandle const& node, int kid_number) | 578 | +NNTreeIterator::addPathElement(QPDFObjectHandle const& a_node, int kid_number) |
| 579 | { | 579 | { |
| 580 | - this->path.emplace_back(node, kid_number); | 580 | + path.emplace_back(a_node, kid_number); |
| 581 | } | 581 | } |
| 582 | 582 | ||
| 583 | bool | 583 | bool |
| 584 | -NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | 584 | +NNTreeIterator::deepen(QPDFObjectHandle a_node, bool first, bool allow_empty) |
| 585 | { | 585 | { |
| 586 | // Starting at this node, descend through the first or last kid until we reach a node with | 586 | // Starting at this node, descend through the first or last kid until we reach a node with |
| 587 | // items. If we succeed, return true; otherwise return false and leave path alone. | 587 | // items. If we succeed, return true; otherwise return false and leave path alone. |
| 588 | 588 | ||
| 589 | - auto opath = this->path; | 589 | + auto opath = path; |
| 590 | bool failed = false; | 590 | bool failed = false; |
| 591 | 591 | ||
| 592 | QPDFObjGen::set seen; | 592 | QPDFObjGen::set seen; |
| 593 | - for (auto const& i: this->path) { | 593 | + for (auto const& i: path) { |
| 594 | seen.add(i.node); | 594 | seen.add(i.node); |
| 595 | } | 595 | } |
| 596 | while (!failed) { | 596 | while (!failed) { |
| 597 | - if (!seen.add(node)) { | 597 | + if (!seen.add(a_node)) { |
| 598 | QTC::TC("qpdf", "NNTree deepen: loop"); | 598 | QTC::TC("qpdf", "NNTree deepen: loop"); |
| 599 | - warn(impl.qpdf, node, "loop detected while traversing name/number tree"); | 599 | + warn(impl.qpdf, a_node, "loop detected while traversing name/number tree"); |
| 600 | failed = true; | 600 | failed = true; |
| 601 | break; | 601 | break; |
| 602 | } | 602 | } |
| 603 | 603 | ||
| 604 | - if (!node.isDictionary()) { | 604 | + if (!a_node.isDictionary()) { |
| 605 | QTC::TC("qpdf", "NNTree node is not a dictionary"); | 605 | QTC::TC("qpdf", "NNTree node is not a dictionary"); |
| 606 | - warn(impl.qpdf, node, "non-dictionary node while traversing name/number tree"); | 606 | + warn(impl.qpdf, a_node, "non-dictionary node while traversing name/number tree"); |
| 607 | failed = true; | 607 | failed = true; |
| 608 | break; | 608 | break; |
| 609 | } | 609 | } |
| 610 | 610 | ||
| 611 | - auto kids = node.getKey("/Kids"); | 611 | + auto kids = a_node.getKey("/Kids"); |
| 612 | int nkids = kids.isArray() ? kids.getArrayNItems() : 0; | 612 | int nkids = kids.isArray() ? kids.getArrayNItems() : 0; |
| 613 | - auto items = node.getKey(impl.details.itemsKey()); | 613 | + auto items = a_node.getKey(impl.details.itemsKey()); |
| 614 | int nitems = items.isArray() ? items.getArrayNItems() : 0; | 614 | int nitems = items.isArray() ? items.getArrayNItems() : 0; |
| 615 | if (nitems > 0) { | 615 | if (nitems > 0) { |
| 616 | - setItemNumber(node, first ? 0 : nitems - 2); | 616 | + setItemNumber(a_node, first ? 0 : nitems - 2); |
| 617 | break; | 617 | break; |
| 618 | } else if (nkids > 0) { | 618 | } else if (nkids > 0) { |
| 619 | int kid_number = first ? 0 : nkids - 1; | 619 | int kid_number = first ? 0 : nkids - 1; |
| 620 | - addPathElement(node, kid_number); | 620 | + addPathElement(a_node, kid_number); |
| 621 | auto next = kids.getArrayItem(kid_number); | 621 | auto next = kids.getArrayItem(kid_number); |
| 622 | if (!next.isIndirect()) { | 622 | if (!next.isIndirect()) { |
| 623 | if (impl.auto_repair) { | 623 | if (impl.auto_repair) { |
| 624 | QTC::TC("qpdf", "NNTree fix indirect kid"); | 624 | QTC::TC("qpdf", "NNTree fix indirect kid"); |
| 625 | warn( | 625 | warn( |
| 626 | impl.qpdf, | 626 | impl.qpdf, |
| 627 | - node, | 627 | + a_node, |
| 628 | ("converting kid number " + std::to_string(kid_number) + | 628 | ("converting kid number " + std::to_string(kid_number) + |
| 629 | " to an indirect object")); | 629 | " to an indirect object")); |
| 630 | next = impl.qpdf.makeIndirectObject(next); | 630 | next = impl.qpdf.makeIndirectObject(next); |
| @@ -633,21 +633,21 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | @@ -633,21 +633,21 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | ||
| 633 | QTC::TC("qpdf", "NNTree warn indirect kid"); | 633 | QTC::TC("qpdf", "NNTree warn indirect kid"); |
| 634 | warn( | 634 | warn( |
| 635 | impl.qpdf, | 635 | impl.qpdf, |
| 636 | - node, | 636 | + a_node, |
| 637 | ("kid number " + std::to_string(kid_number) + | 637 | ("kid number " + std::to_string(kid_number) + |
| 638 | " is not an indirect object")); | 638 | " is not an indirect object")); |
| 639 | } | 639 | } |
| 640 | } | 640 | } |
| 641 | - node = next; | 641 | + a_node = next; |
| 642 | } else if (allow_empty && items.isArray()) { | 642 | } else if (allow_empty && items.isArray()) { |
| 643 | QTC::TC("qpdf", "NNTree deepen found empty"); | 643 | QTC::TC("qpdf", "NNTree deepen found empty"); |
| 644 | - setItemNumber(node, -1); | 644 | + setItemNumber(a_node, -1); |
| 645 | break; | 645 | break; |
| 646 | } else { | 646 | } else { |
| 647 | QTC::TC("qpdf", "NNTree deepen: invalid node"); | 647 | QTC::TC("qpdf", "NNTree deepen: invalid node"); |
| 648 | warn( | 648 | warn( |
| 649 | impl.qpdf, | 649 | impl.qpdf, |
| 650 | - node, | 650 | + a_node, |
| 651 | ("name/number tree node has neither non-empty " + impl.details.itemsKey() + | 651 | ("name/number tree node has neither non-empty " + impl.details.itemsKey() + |
| 652 | " nor /Kids")); | 652 | " nor /Kids")); |
| 653 | failed = true; | 653 | failed = true; |
| @@ -655,7 +655,7 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | @@ -655,7 +655,7 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | ||
| 655 | } | 655 | } |
| 656 | } | 656 | } |
| 657 | if (failed) { | 657 | if (failed) { |
| 658 | - this->path = opath; | 658 | + path = opath; |
| 659 | return false; | 659 | return false; |
| 660 | } | 660 | } |
| 661 | return true; | 661 | return true; |
| @@ -671,16 +671,16 @@ NNTreeImpl::NNTreeImpl( | @@ -671,16 +671,16 @@ NNTreeImpl::NNTreeImpl( | ||
| 671 | } | 671 | } |
| 672 | 672 | ||
| 673 | void | 673 | void |
| 674 | -NNTreeImpl::setSplitThreshold(int split_threshold) | 674 | +NNTreeImpl::setSplitThreshold(int threshold) |
| 675 | { | 675 | { |
| 676 | - this->split_threshold = split_threshold; | 676 | + split_threshold = threshold; |
| 677 | } | 677 | } |
| 678 | 678 | ||
| 679 | NNTreeImpl::iterator | 679 | NNTreeImpl::iterator |
| 680 | NNTreeImpl::begin() | 680 | NNTreeImpl::begin() |
| 681 | { | 681 | { |
| 682 | iterator result(*this); | 682 | iterator result(*this); |
| 683 | - result.deepen(this->oh, true, true); | 683 | + result.deepen(oh, true, true); |
| 684 | return result; | 684 | return result; |
| 685 | } | 685 | } |
| 686 | 686 | ||
| @@ -694,7 +694,7 @@ NNTreeImpl::iterator | @@ -694,7 +694,7 @@ NNTreeImpl::iterator | ||
| 694 | NNTreeImpl::last() | 694 | NNTreeImpl::last() |
| 695 | { | 695 | { |
| 696 | iterator result(*this); | 696 | iterator result(*this); |
| 697 | - result.deepen(this->oh, false, true); | 697 | + result.deepen(oh, false, true); |
| 698 | return result; | 698 | return result; |
| 699 | } | 699 | } |
| 700 | 700 | ||
| @@ -782,10 +782,7 @@ NNTreeImpl::compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int i | @@ -782,10 +782,7 @@ NNTreeImpl::compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int i | ||
| 782 | if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) && | 782 | if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) && |
| 783 | details.keyValid(items.getArrayItem(2 * idx))))) { | 783 | details.keyValid(items.getArrayItem(2 * idx))))) { |
| 784 | QTC::TC("qpdf", "NNTree item is wrong type"); | 784 | QTC::TC("qpdf", "NNTree item is wrong type"); |
| 785 | - error( | ||
| 786 | - qpdf, | ||
| 787 | - this->oh, | ||
| 788 | - ("item at index " + std::to_string(2 * idx) + " is not the right type")); | 785 | + error(qpdf, oh, ("item at index " + std::to_string(2 * idx) + " is not the right type")); |
| 789 | } | 786 | } |
| 790 | return details.compareKeys(key, items.getArrayItem(2 * idx)); | 787 | return details.compareKeys(key, items.getArrayItem(2 * idx)); |
| 791 | } | 788 | } |
| @@ -796,7 +793,7 @@ NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx | @@ -796,7 +793,7 @@ NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx | ||
| 796 | if (!(kids.isArray() && (idx < kids.getArrayNItems()) && | 793 | if (!(kids.isArray() && (idx < kids.getArrayNItems()) && |
| 797 | kids.getArrayItem(idx).isDictionary())) { | 794 | kids.getArrayItem(idx).isDictionary())) { |
| 798 | QTC::TC("qpdf", "NNTree kid is invalid"); | 795 | QTC::TC("qpdf", "NNTree kid is invalid"); |
| 799 | - error(qpdf, this->oh, "invalid kid at index " + std::to_string(idx)); | 796 | + error(qpdf, oh, "invalid kid at index " + std::to_string(idx)); |
| 800 | } | 797 | } |
| 801 | return withinLimits(key, kids.getArrayItem(idx)); | 798 | return withinLimits(key, kids.getArrayItem(idx)); |
| 802 | } | 799 | } |
| @@ -810,8 +807,8 @@ NNTreeImpl::repair() | @@ -810,8 +807,8 @@ NNTreeImpl::repair() | ||
| 810 | for (auto const& i: *this) { | 807 | for (auto const& i: *this) { |
| 811 | repl.insert(i.first, i.second); | 808 | repl.insert(i.first, i.second); |
| 812 | } | 809 | } |
| 813 | - this->oh.replaceKey("/Kids", new_node.getKey("/Kids")); | ||
| 814 | - this->oh.replaceKey(details.itemsKey(), new_node.getKey(details.itemsKey())); | 810 | + oh.replaceKey("/Kids", new_node.getKey("/Kids")); |
| 811 | + oh.replaceKey(details.itemsKey(), new_node.getKey(details.itemsKey())); | ||
| 815 | } | 812 | } |
| 816 | 813 | ||
| 817 | NNTreeImpl::iterator | 814 | NNTreeImpl::iterator |
| @@ -820,9 +817,9 @@ NNTreeImpl::find(QPDFObjectHandle key, bool return_prev_if_not_found) | @@ -820,9 +817,9 @@ NNTreeImpl::find(QPDFObjectHandle key, bool return_prev_if_not_found) | ||
| 820 | try { | 817 | try { |
| 821 | return findInternal(key, return_prev_if_not_found); | 818 | return findInternal(key, return_prev_if_not_found); |
| 822 | } catch (QPDFExc& e) { | 819 | } catch (QPDFExc& e) { |
| 823 | - if (this->auto_repair) { | 820 | + if (auto_repair) { |
| 824 | QTC::TC("qpdf", "NNTree repair"); | 821 | QTC::TC("qpdf", "NNTree repair"); |
| 825 | - warn(qpdf, this->oh, std::string("attempting to repair after error: ") + e.what()); | 822 | + warn(qpdf, oh, std::string("attempting to repair after error: ") + e.what()); |
| 826 | repair(); | 823 | repair(); |
| 827 | return findInternal(key, return_prev_if_not_found); | 824 | return findInternal(key, return_prev_if_not_found); |
| 828 | } else { | 825 | } else { |
| @@ -856,7 +853,7 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found) | @@ -856,7 +853,7 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found) | ||
| 856 | } | 853 | } |
| 857 | 854 | ||
| 858 | QPDFObjGen::set seen; | 855 | QPDFObjGen::set seen; |
| 859 | - auto node = this->oh; | 856 | + auto node = oh; |
| 860 | iterator result(*this); | 857 | iterator result(*this); |
| 861 | 858 | ||
| 862 | while (true) { | 859 | while (true) { |
| @@ -907,7 +904,7 @@ NNTreeImpl::insertFirst(QPDFObjectHandle key, QPDFObjectHandle value) | @@ -907,7 +904,7 @@ NNTreeImpl::insertFirst(QPDFObjectHandle key, QPDFObjectHandle value) | ||
| 907 | } | 904 | } |
| 908 | if (!(items.isArray())) { | 905 | if (!(items.isArray())) { |
| 909 | QTC::TC("qpdf", "NNTree no valid items node in insertFirst"); | 906 | QTC::TC("qpdf", "NNTree no valid items node in insertFirst"); |
| 910 | - error(qpdf, this->oh, "unable to find a valid items node"); | 907 | + error(qpdf, oh, "unable to find a valid items node"); |
| 911 | } | 908 | } |
| 912 | items.insertItem(0, key); | 909 | items.insertItem(0, key); |
| 913 | items.insertItem(1, value); | 910 | items.insertItem(1, value); |
libqpdf/Pl_ASCII85Decoder.cc
| @@ -57,7 +57,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) | @@ -57,7 +57,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) | ||
| 57 | break; | 57 | break; |
| 58 | 58 | ||
| 59 | default: | 59 | default: |
| 60 | - if ((buf[i] < 33) || (buf[i] > 117)) { | 60 | + if (buf[i] < 33 || buf[i] > 117) { |
| 61 | error = true; | 61 | error = true; |
| 62 | throw std::runtime_error("character out of range during base 85 decode"); | 62 | throw std::runtime_error("character out of range during base 85 decode"); |
| 63 | } else { | 63 | } else { |
libqpdf/Pl_ASCIIHexDecoder.cc
| @@ -17,7 +17,7 @@ Pl_ASCIIHexDecoder::Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next) : | @@ -17,7 +17,7 @@ Pl_ASCIIHexDecoder::Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next) : | ||
| 17 | void | 17 | void |
| 18 | Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) | 18 | Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) |
| 19 | { | 19 | { |
| 20 | - if (this->eod) { | 20 | + if (eod) { |
| 21 | return; | 21 | return; |
| 22 | } | 22 | } |
| 23 | for (size_t i = 0; i < len; ++i) { | 23 | for (size_t i = 0; i < len; ++i) { |
| @@ -34,14 +34,14 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) | @@ -34,14 +34,14 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) | ||
| 34 | break; | 34 | break; |
| 35 | 35 | ||
| 36 | case '>': | 36 | case '>': |
| 37 | - this->eod = true; | 37 | + eod = true; |
| 38 | flush(); | 38 | flush(); |
| 39 | break; | 39 | break; |
| 40 | 40 | ||
| 41 | default: | 41 | default: |
| 42 | - if (((ch >= '0') && (ch <= '9')) || ((ch >= 'A') && (ch <= 'F'))) { | ||
| 43 | - this->inbuf[this->pos++] = ch; | ||
| 44 | - if (this->pos == 2) { | 42 | + if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) { |
| 43 | + inbuf[pos++] = ch; | ||
| 44 | + if (pos == 2) { | ||
| 45 | flush(); | 45 | flush(); |
| 46 | } | 46 | } |
| 47 | } else { | 47 | } else { |
| @@ -52,7 +52,7 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) | @@ -52,7 +52,7 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) | ||
| 52 | } | 52 | } |
| 53 | break; | 53 | break; |
| 54 | } | 54 | } |
| 55 | - if (this->eod) { | 55 | + if (eod) { |
| 56 | break; | 56 | break; |
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| @@ -61,26 +61,26 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) | @@ -61,26 +61,26 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) | ||
| 61 | void | 61 | void |
| 62 | Pl_ASCIIHexDecoder::flush() | 62 | Pl_ASCIIHexDecoder::flush() |
| 63 | { | 63 | { |
| 64 | - if (this->pos == 0) { | 64 | + if (pos == 0) { |
| 65 | QTC::TC("libtests", "Pl_ASCIIHexDecoder no-op flush"); | 65 | QTC::TC("libtests", "Pl_ASCIIHexDecoder no-op flush"); |
| 66 | return; | 66 | return; |
| 67 | } | 67 | } |
| 68 | int b[2]; | 68 | int b[2]; |
| 69 | for (int i = 0; i < 2; ++i) { | 69 | for (int i = 0; i < 2; ++i) { |
| 70 | - if (this->inbuf[i] >= 'A') { | ||
| 71 | - b[i] = this->inbuf[i] - 'A' + 10; | 70 | + if (inbuf[i] >= 'A') { |
| 71 | + b[i] = inbuf[i] - 'A' + 10; | ||
| 72 | } else { | 72 | } else { |
| 73 | - b[i] = this->inbuf[i] - '0'; | 73 | + b[i] = inbuf[i] - '0'; |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | auto ch = static_cast<unsigned char>((b[0] << 4) + b[1]); | 76 | auto ch = static_cast<unsigned char>((b[0] << 4) + b[1]); |
| 77 | 77 | ||
| 78 | - QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", (this->pos == 2) ? 0 : 1); | 78 | + QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", (pos == 2) ? 0 : 1); |
| 79 | // Reset before calling getNext()->write in case that throws an exception. | 79 | // Reset before calling getNext()->write in case that throws an exception. |
| 80 | - this->pos = 0; | ||
| 81 | - this->inbuf[0] = '0'; | ||
| 82 | - this->inbuf[1] = '0'; | ||
| 83 | - this->inbuf[2] = '\0'; | 80 | + pos = 0; |
| 81 | + inbuf[0] = '0'; | ||
| 82 | + inbuf[1] = '0'; | ||
| 83 | + inbuf[2] = '\0'; | ||
| 84 | 84 | ||
| 85 | next()->write(&ch, 1); | 85 | next()->write(&ch, 1); |
| 86 | } | 86 | } |
libqpdf/Pl_Base64.cc
| @@ -102,17 +102,17 @@ Pl_Base64::flush_decode() | @@ -102,17 +102,17 @@ Pl_Base64::flush_decode() | ||
| 102 | for (size_t i = 0; i < 4; ++i) { | 102 | for (size_t i = 0; i < 4; ++i) { |
| 103 | int v = 0; | 103 | int v = 0; |
| 104 | char ch = to_c(buf[i]); | 104 | char ch = to_c(buf[i]); |
| 105 | - if ((ch >= 'A') && (ch <= 'Z')) { | 105 | + if (ch >= 'A' && ch <= 'Z') { |
| 106 | v = ch - 'A'; | 106 | v = ch - 'A'; |
| 107 | - } else if ((ch >= 'a') && (ch <= 'z')) { | 107 | + } else if (ch >= 'a' && ch <= 'z') { |
| 108 | v = ch - 'a' + 26; | 108 | v = ch - 'a' + 26; |
| 109 | - } else if ((ch >= '0') && (ch <= '9')) { | 109 | + } else if (ch >= '0' && ch <= '9') { |
| 110 | v = ch - '0' + 52; | 110 | v = ch - '0' + 52; |
| 111 | - } else if ((ch == '+') || (ch == '-')) { | 111 | + } else if (ch == '+' || ch == '-') { |
| 112 | v = 62; | 112 | v = 62; |
| 113 | - } else if ((ch == '/') || (ch == '_')) { | 113 | + } else if (ch == '/' || ch == '_') { |
| 114 | v = 63; | 114 | v = 63; |
| 115 | - } else if ((ch == '=') && ((i == 3) || ((i == 2) && (buf[3] == '=')))) { | 115 | + } else if (ch == '=' && (i == 3 || (i == 2 && buf[3] == '='))) { |
| 116 | ++pad; | 116 | ++pad; |
| 117 | end_of_data = true; | 117 | end_of_data = true; |
| 118 | v = 0; | 118 | v = 0; |
| @@ -134,7 +134,7 @@ Pl_Base64::flush_decode() | @@ -134,7 +134,7 @@ Pl_Base64::flush_decode() | ||
| 134 | void | 134 | void |
| 135 | Pl_Base64::flush_encode() | 135 | Pl_Base64::flush_encode() |
| 136 | { | 136 | { |
| 137 | - int outval = ((buf[0] << 16) | (buf[1] << 8) | (buf[2])); | 137 | + int outval = ((buf[0] << 16) | (buf[1] << 8) | buf[2]); |
| 138 | unsigned char out[4] = { | 138 | unsigned char out[4] = { |
| 139 | to_uc(outval >> 18), | 139 | to_uc(outval >> 18), |
| 140 | to_uc(0x3f & (outval >> 12)), | 140 | to_uc(0x3f & (outval >> 12)), |
libqpdf/Pl_LZWDecoder.cc
| @@ -23,8 +23,8 @@ Pl_LZWDecoder::write(unsigned char const* bytes, size_t len) | @@ -23,8 +23,8 @@ Pl_LZWDecoder::write(unsigned char const* bytes, size_t len) | ||
| 23 | if (next_char_ == 3) { | 23 | if (next_char_ == 3) { |
| 24 | next_char_ = 0; | 24 | next_char_ = 0; |
| 25 | } | 25 | } |
| 26 | - this->bits_available += 8; | ||
| 27 | - if (this->bits_available >= this->code_size) { | 26 | + bits_available += 8; |
| 27 | + if (bits_available >= code_size) { | ||
| 28 | sendNextCode(); | 28 | sendNextCode(); |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| @@ -39,12 +39,12 @@ Pl_LZWDecoder::finish() | @@ -39,12 +39,12 @@ Pl_LZWDecoder::finish() | ||
| 39 | void | 39 | void |
| 40 | Pl_LZWDecoder::sendNextCode() | 40 | Pl_LZWDecoder::sendNextCode() |
| 41 | { | 41 | { |
| 42 | - unsigned int high = this->byte_pos; | ||
| 43 | - unsigned int med = (this->byte_pos + 1) % 3; | ||
| 44 | - unsigned int low = (this->byte_pos + 2) % 3; | 42 | + unsigned int high = byte_pos; |
| 43 | + unsigned int med = (byte_pos + 1) % 3; | ||
| 44 | + unsigned int low = (byte_pos + 2) % 3; | ||
| 45 | 45 | ||
| 46 | - unsigned int bits_from_high = 8 - this->bit_pos; | ||
| 47 | - unsigned int bits_from_med = this->code_size - bits_from_high; | 46 | + unsigned int bits_from_high = 8 - bit_pos; |
| 47 | + unsigned int bits_from_med = code_size - bits_from_high; | ||
| 48 | unsigned int bits_from_low = 0; | 48 | unsigned int bits_from_low = 0; |
| 49 | if (bits_from_med > 8) { | 49 | if (bits_from_med > 8) { |
| 50 | bits_from_low = bits_from_med - 8; | 50 | bits_from_low = bits_from_med - 8; |
| @@ -54,23 +54,23 @@ Pl_LZWDecoder::sendNextCode() | @@ -54,23 +54,23 @@ Pl_LZWDecoder::sendNextCode() | ||
| 54 | unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U); | 54 | unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U); |
| 55 | unsigned int low_mask = 0xff - ((1U << (8 - bits_from_low)) - 1U); | 55 | unsigned int low_mask = 0xff - ((1U << (8 - bits_from_low)) - 1U); |
| 56 | unsigned int code = 0; | 56 | unsigned int code = 0; |
| 57 | - code += (this->buf[high] & high_mask) << bits_from_med; | ||
| 58 | - code += ((this->buf[med] & med_mask) >> (8 - bits_from_med)); | 57 | + code += (buf[high] & high_mask) << bits_from_med; |
| 58 | + code += ((buf[med] & med_mask) >> (8 - bits_from_med)); | ||
| 59 | if (bits_from_low) { | 59 | if (bits_from_low) { |
| 60 | code <<= bits_from_low; | 60 | code <<= bits_from_low; |
| 61 | - code += ((this->buf[low] & low_mask) >> (8 - bits_from_low)); | ||
| 62 | - this->byte_pos = low; | ||
| 63 | - this->bit_pos = bits_from_low; | 61 | + code += ((buf[low] & low_mask) >> (8 - bits_from_low)); |
| 62 | + byte_pos = low; | ||
| 63 | + bit_pos = bits_from_low; | ||
| 64 | } else { | 64 | } else { |
| 65 | - this->byte_pos = med; | ||
| 66 | - this->bit_pos = bits_from_med; | 65 | + byte_pos = med; |
| 66 | + bit_pos = bits_from_med; | ||
| 67 | } | 67 | } |
| 68 | - if (this->bit_pos == 8) { | ||
| 69 | - this->bit_pos = 0; | ||
| 70 | - ++this->byte_pos; | ||
| 71 | - this->byte_pos %= 3; | 68 | + if (bit_pos == 8) { |
| 69 | + bit_pos = 0; | ||
| 70 | + ++byte_pos; | ||
| 71 | + byte_pos %= 3; | ||
| 72 | } | 72 | } |
| 73 | - this->bits_available -= this->code_size; | 73 | + bits_available -= code_size; |
| 74 | 74 | ||
| 75 | handleCode(code); | 75 | handleCode(code); |
| 76 | } | 76 | } |
| @@ -102,12 +102,12 @@ Pl_LZWDecoder::addToTable(unsigned char c) | @@ -102,12 +102,12 @@ Pl_LZWDecoder::addToTable(unsigned char c) | ||
| 102 | unsigned char const* last_data = nullptr; | 102 | unsigned char const* last_data = nullptr; |
| 103 | unsigned char tmp[1]; | 103 | unsigned char tmp[1]; |
| 104 | 104 | ||
| 105 | - if (this->last_code < 256) { | ||
| 106 | - tmp[0] = static_cast<unsigned char>(this->last_code); | 105 | + if (last_code < 256) { |
| 106 | + tmp[0] = static_cast<unsigned char>(last_code); | ||
| 107 | last_data = tmp; | 107 | last_data = tmp; |
| 108 | last_size = 1; | 108 | last_size = 1; |
| 109 | - } else if (this->last_code > 257) { | ||
| 110 | - unsigned int idx = this->last_code - 258; | 109 | + } else if (last_code > 257) { |
| 110 | + unsigned int idx = last_code - 258; | ||
| 111 | if (idx >= table.size()) { | 111 | if (idx >= table.size()) { |
| 112 | throw std::runtime_error("Pl_LZWDecoder::addToTable: table overflow"); | 112 | throw std::runtime_error("Pl_LZWDecoder::addToTable: table overflow"); |
| 113 | } | 113 | } |
| @@ -116,34 +116,34 @@ Pl_LZWDecoder::addToTable(unsigned char c) | @@ -116,34 +116,34 @@ Pl_LZWDecoder::addToTable(unsigned char c) | ||
| 116 | last_size = QIntC::to_uint(b.getSize()); | 116 | last_size = QIntC::to_uint(b.getSize()); |
| 117 | } else { | 117 | } else { |
| 118 | throw std::runtime_error( | 118 | throw std::runtime_error( |
| 119 | - "Pl_LZWDecoder::addToTable called with invalid code (" + | ||
| 120 | - std::to_string(this->last_code) + ")"); | 119 | + "Pl_LZWDecoder::addToTable called with invalid code (" + std::to_string(last_code) + |
| 120 | + ")"); | ||
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | Buffer entry(1 + last_size); | 123 | Buffer entry(1 + last_size); |
| 124 | unsigned char* new_data = entry.getBuffer(); | 124 | unsigned char* new_data = entry.getBuffer(); |
| 125 | memcpy(new_data, last_data, last_size); | 125 | memcpy(new_data, last_data, last_size); |
| 126 | new_data[last_size] = c; | 126 | new_data[last_size] = c; |
| 127 | - this->table.push_back(std::move(entry)); | 127 | + table.push_back(std::move(entry)); |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | void | 130 | void |
| 131 | Pl_LZWDecoder::handleCode(unsigned int code) | 131 | Pl_LZWDecoder::handleCode(unsigned int code) |
| 132 | { | 132 | { |
| 133 | - if (this->eod) { | 133 | + if (eod) { |
| 134 | return; | 134 | return; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | if (code == 256) { | 137 | if (code == 256) { |
| 138 | - if (!this->table.empty()) { | 138 | + if (!table.empty()) { |
| 139 | QTC::TC("libtests", "Pl_LZWDecoder intermediate reset"); | 139 | QTC::TC("libtests", "Pl_LZWDecoder intermediate reset"); |
| 140 | } | 140 | } |
| 141 | - this->table.clear(); | ||
| 142 | - this->code_size = 9; | 141 | + table.clear(); |
| 142 | + code_size = 9; | ||
| 143 | } else if (code == 257) { | 143 | } else if (code == 257) { |
| 144 | - this->eod = true; | 144 | + eod = true; |
| 145 | } else { | 145 | } else { |
| 146 | - if (this->last_code != 256) { | 146 | + if (last_code != 256) { |
| 147 | // 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 |
| 148 | // first character of what we're reading now. | 148 | // first character of what we're reading now. |
| 149 | unsigned char next_c = '\0'; | 149 | unsigned char next_c = '\0'; |
| @@ -159,7 +159,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) | @@ -159,7 +159,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) | ||
| 159 | // 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 |
| 160 | // 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. |
| 161 | QTC::TC("libtests", "Pl_LZWDecoder last was table size"); | 161 | QTC::TC("libtests", "Pl_LZWDecoder last was table size"); |
| 162 | - next_c = getFirstChar(this->last_code); | 162 | + next_c = getFirstChar(last_code); |
| 163 | } else { | 163 | } else { |
| 164 | next_c = getFirstChar(code); | 164 | next_c = getFirstChar(code); |
| 165 | } | 165 | } |
| @@ -171,7 +171,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) | @@ -171,7 +171,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) | ||
| 171 | addToTable(next_c); | 171 | addToTable(next_c); |
| 172 | unsigned int change_idx = new_idx + code_change_delta; | 172 | unsigned int change_idx = new_idx + code_change_delta; |
| 173 | if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) { | 173 | if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) { |
| 174 | - ++this->code_size; | 174 | + ++code_size; |
| 175 | } | 175 | } |
| 176 | } | 176 | } |
| 177 | 177 | ||
| @@ -188,5 +188,5 @@ Pl_LZWDecoder::handleCode(unsigned int code) | @@ -188,5 +188,5 @@ Pl_LZWDecoder::handleCode(unsigned int code) | ||
| 188 | } | 188 | } |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | - this->last_code = code; | 191 | + last_code = code; |
| 192 | } | 192 | } |
libqpdf/Pl_MD5.cc
| @@ -13,10 +13,10 @@ Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) : | @@ -13,10 +13,10 @@ Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) : | ||
| 13 | void | 13 | void |
| 14 | Pl_MD5::write(unsigned char const* buf, size_t len) | 14 | Pl_MD5::write(unsigned char const* buf, size_t len) |
| 15 | { | 15 | { |
| 16 | - if (this->enabled) { | ||
| 17 | - if (!this->in_progress) { | ||
| 18 | - this->md5.reset(); | ||
| 19 | - this->in_progress = true; | 16 | + if (enabled) { |
| 17 | + if (!in_progress) { | ||
| 18 | + md5.reset(); | ||
| 19 | + in_progress = true; | ||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. | 22 | // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. |
| @@ -25,7 +25,7 @@ Pl_MD5::write(unsigned char const* buf, size_t len) | @@ -25,7 +25,7 @@ Pl_MD5::write(unsigned char const* buf, size_t len) | ||
| 25 | unsigned char const* data = buf; | 25 | unsigned char const* data = buf; |
| 26 | while (bytes_left > 0) { | 26 | while (bytes_left > 0) { |
| 27 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); | 27 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); |
| 28 | - this->md5.encodeDataIncrementally(reinterpret_cast<char const*>(data), bytes); | 28 | + md5.encodeDataIncrementally(reinterpret_cast<char const*>(data), bytes); |
| 29 | bytes_left -= bytes; | 29 | bytes_left -= bytes; |
| 30 | data += bytes; | 30 | data += bytes; |
| 31 | } | 31 | } |
| @@ -38,29 +38,29 @@ void | @@ -38,29 +38,29 @@ void | ||
| 38 | Pl_MD5::finish() | 38 | Pl_MD5::finish() |
| 39 | { | 39 | { |
| 40 | next()->finish(); | 40 | next()->finish(); |
| 41 | - if (!this->persist_across_finish) { | ||
| 42 | - this->in_progress = false; | 41 | + if (!persist_across_finish) { |
| 42 | + in_progress = false; | ||
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | void | 46 | void |
| 47 | -Pl_MD5::enable(bool enabled) | 47 | +Pl_MD5::enable(bool is_enabled) |
| 48 | { | 48 | { |
| 49 | - this->enabled = enabled; | 49 | + enabled = is_enabled; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | void | 52 | void |
| 53 | Pl_MD5::persistAcrossFinish(bool persist) | 53 | Pl_MD5::persistAcrossFinish(bool persist) |
| 54 | { | 54 | { |
| 55 | - this->persist_across_finish = persist; | 55 | + persist_across_finish = persist; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | std::string | 58 | std::string |
| 59 | Pl_MD5::getHexDigest() | 59 | Pl_MD5::getHexDigest() |
| 60 | { | 60 | { |
| 61 | - if (!this->enabled) { | 61 | + if (!enabled) { |
| 62 | throw std::logic_error("digest requested for a disabled MD5 Pipeline"); | 62 | throw std::logic_error("digest requested for a disabled MD5 Pipeline"); |
| 63 | } | 63 | } |
| 64 | - this->in_progress = false; | ||
| 65 | - return this->md5.unparse(); | 64 | + in_progress = false; |
| 65 | + return md5.unparse(); | ||
| 66 | } | 66 | } |
libqpdf/Pl_SHA2.cc
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | #include <qpdf/QPDFCryptoProvider.hh> | 3 | #include <qpdf/QPDFCryptoProvider.hh> |
| 4 | #include <qpdf/QUtil.hh> | 4 | #include <qpdf/QUtil.hh> |
| 5 | + | ||
| 5 | #include <stdexcept> | 6 | #include <stdexcept> |
| 6 | 7 | ||
| 7 | Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) : | 8 | Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) : |
| @@ -15,8 +16,8 @@ Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) : | @@ -15,8 +16,8 @@ Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) : | ||
| 15 | void | 16 | void |
| 16 | Pl_SHA2::write(unsigned char const* buf, size_t len) | 17 | Pl_SHA2::write(unsigned char const* buf, size_t len) |
| 17 | { | 18 | { |
| 18 | - if (!this->in_progress) { | ||
| 19 | - this->in_progress = true; | 19 | + if (!in_progress) { |
| 20 | + in_progress = true; | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. | 23 | // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. |
| @@ -25,7 +26,7 @@ Pl_SHA2::write(unsigned char const* buf, size_t len) | @@ -25,7 +26,7 @@ Pl_SHA2::write(unsigned char const* buf, size_t len) | ||
| 25 | unsigned char const* data = buf; | 26 | unsigned char const* data = buf; |
| 26 | while (bytes_left > 0) { | 27 | while (bytes_left > 0) { |
| 27 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); | 28 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); |
| 28 | - this->crypto->SHA2_update(data, bytes); | 29 | + crypto->SHA2_update(data, bytes); |
| 29 | bytes_left -= bytes; | 30 | bytes_left -= bytes; |
| 30 | data += bytes; | 31 | data += bytes; |
| 31 | } | 32 | } |
| @@ -41,33 +42,33 @@ Pl_SHA2::finish() | @@ -41,33 +42,33 @@ Pl_SHA2::finish() | ||
| 41 | if (next()) { | 42 | if (next()) { |
| 42 | next()->finish(); | 43 | next()->finish(); |
| 43 | } | 44 | } |
| 44 | - this->crypto->SHA2_finalize(); | ||
| 45 | - this->in_progress = false; | 45 | + crypto->SHA2_finalize(); |
| 46 | + in_progress = false; | ||
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | void | 49 | void |
| 49 | Pl_SHA2::resetBits(int bits) | 50 | Pl_SHA2::resetBits(int bits) |
| 50 | { | 51 | { |
| 51 | - if (this->in_progress) { | 52 | + if (in_progress) { |
| 52 | throw std::logic_error("bit reset requested for in-progress SHA2 Pipeline"); | 53 | throw std::logic_error("bit reset requested for in-progress SHA2 Pipeline"); |
| 53 | } | 54 | } |
| 54 | - this->crypto = QPDFCryptoProvider::getImpl(); | ||
| 55 | - this->crypto->SHA2_init(bits); | 55 | + crypto = QPDFCryptoProvider::getImpl(); |
| 56 | + crypto->SHA2_init(bits); | ||
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | std::string | 59 | std::string |
| 59 | Pl_SHA2::getRawDigest() | 60 | Pl_SHA2::getRawDigest() |
| 60 | { | 61 | { |
| 61 | - if (this->in_progress) { | 62 | + if (in_progress) { |
| 62 | throw std::logic_error("digest requested for in-progress SHA2 Pipeline"); | 63 | throw std::logic_error("digest requested for in-progress SHA2 Pipeline"); |
| 63 | } | 64 | } |
| 64 | - return this->crypto->SHA2_digest(); | 65 | + return crypto->SHA2_digest(); |
| 65 | } | 66 | } |
| 66 | 67 | ||
| 67 | std::string | 68 | std::string |
| 68 | Pl_SHA2::getHexDigest() | 69 | Pl_SHA2::getHexDigest() |
| 69 | { | 70 | { |
| 70 | - if (this->in_progress) { | 71 | + if (in_progress) { |
| 71 | throw std::logic_error("digest requested for in-progress SHA2 Pipeline"); | 72 | throw std::logic_error("digest requested for in-progress SHA2 Pipeline"); |
| 72 | } | 73 | } |
| 73 | return QUtil::hex_encode(getRawDigest()); | 74 | return QUtil::hex_encode(getRawDigest()); |
libqpdf/QPDFCrypto_gnutls.cc
| @@ -18,14 +18,14 @@ QPDFCrypto_gnutls::QPDFCrypto_gnutls() : | @@ -18,14 +18,14 @@ QPDFCrypto_gnutls::QPDFCrypto_gnutls() : | ||
| 18 | 18 | ||
| 19 | QPDFCrypto_gnutls::~QPDFCrypto_gnutls() | 19 | QPDFCrypto_gnutls::~QPDFCrypto_gnutls() |
| 20 | { | 20 | { |
| 21 | - if (this->hash_ctx) { | ||
| 22 | - gnutls_hash_deinit(this->hash_ctx, digest); | 21 | + if (hash_ctx) { |
| 22 | + gnutls_hash_deinit(hash_ctx, digest); | ||
| 23 | } | 23 | } |
| 24 | if (cipher_ctx) { | 24 | if (cipher_ctx) { |
| 25 | - gnutls_cipher_deinit(this->cipher_ctx); | 25 | + gnutls_cipher_deinit(cipher_ctx); |
| 26 | } | 26 | } |
| 27 | - this->aes_key_data = nullptr; | ||
| 28 | - this->aes_key_len = 0; | 27 | + aes_key_data = nullptr; |
| 28 | + aes_key_len = 0; | ||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | void | 31 | void |
| @@ -43,9 +43,9 @@ void | @@ -43,9 +43,9 @@ void | ||
| 43 | QPDFCrypto_gnutls::MD5_init() | 43 | QPDFCrypto_gnutls::MD5_init() |
| 44 | { | 44 | { |
| 45 | MD5_finalize(); | 45 | MD5_finalize(); |
| 46 | - int code = gnutls_hash_init(&this->hash_ctx, GNUTLS_DIG_MD5); | 46 | + int code = gnutls_hash_init(&hash_ctx, GNUTLS_DIG_MD5); |
| 47 | if (code < 0) { | 47 | if (code < 0) { |
| 48 | - this->hash_ctx = nullptr; | 48 | + hash_ctx = nullptr; |
| 49 | throw std::runtime_error( | 49 | throw std::runtime_error( |
| 50 | std::string("gnutls: MD5 error: ") + std::string(gnutls_strerror(code))); | 50 | std::string("gnutls: MD5 error: ") + std::string(gnutls_strerror(code))); |
| 51 | } | 51 | } |
| @@ -54,22 +54,22 @@ QPDFCrypto_gnutls::MD5_init() | @@ -54,22 +54,22 @@ QPDFCrypto_gnutls::MD5_init() | ||
| 54 | void | 54 | void |
| 55 | QPDFCrypto_gnutls::MD5_update(unsigned char const* data, size_t len) | 55 | QPDFCrypto_gnutls::MD5_update(unsigned char const* data, size_t len) |
| 56 | { | 56 | { |
| 57 | - gnutls_hash(this->hash_ctx, data, len); | 57 | + gnutls_hash(hash_ctx, data, len); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | void | 60 | void |
| 61 | QPDFCrypto_gnutls::MD5_finalize() | 61 | QPDFCrypto_gnutls::MD5_finalize() |
| 62 | { | 62 | { |
| 63 | - if (this->hash_ctx) { | ||
| 64 | - gnutls_hash_deinit(this->hash_ctx, this->digest); | ||
| 65 | - this->hash_ctx = nullptr; | 63 | + if (hash_ctx) { |
| 64 | + gnutls_hash_deinit(hash_ctx, digest); | ||
| 65 | + hash_ctx = nullptr; | ||
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | void | 69 | void |
| 70 | QPDFCrypto_gnutls::MD5_digest(MD5_Digest d) | 70 | QPDFCrypto_gnutls::MD5_digest(MD5_Digest d) |
| 71 | { | 71 | { |
| 72 | - memcpy(d, this->digest, sizeof(MD5_Digest)); | 72 | + memcpy(d, digest, sizeof(MD5_Digest)); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | void | 75 | void |
| @@ -83,9 +83,9 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) | @@ -83,9 +83,9 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) | ||
| 83 | key.data = const_cast<unsigned char*>(key_data); | 83 | key.data = const_cast<unsigned char*>(key_data); |
| 84 | key.size = QIntC::to_uint(key_len); | 84 | key.size = QIntC::to_uint(key_len); |
| 85 | 85 | ||
| 86 | - int code = gnutls_cipher_init(&this->cipher_ctx, GNUTLS_CIPHER_ARCFOUR_128, &key, nullptr); | 86 | + int code = gnutls_cipher_init(&cipher_ctx, GNUTLS_CIPHER_ARCFOUR_128, &key, nullptr); |
| 87 | if (code < 0) { | 87 | if (code < 0) { |
| 88 | - this->cipher_ctx = nullptr; | 88 | + cipher_ctx = nullptr; |
| 89 | throw std::runtime_error( | 89 | throw std::runtime_error( |
| 90 | std::string("gnutls: RC4 error: ") + std::string(gnutls_strerror(code))); | 90 | std::string("gnutls: RC4 error: ") + std::string(gnutls_strerror(code))); |
| 91 | } | 91 | } |
| @@ -94,15 +94,15 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) | @@ -94,15 +94,15 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) | ||
| 94 | void | 94 | void |
| 95 | QPDFCrypto_gnutls::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) | 95 | QPDFCrypto_gnutls::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) |
| 96 | { | 96 | { |
| 97 | - gnutls_cipher_encrypt2(this->cipher_ctx, in_data, len, out_data, len); | 97 | + gnutls_cipher_encrypt2(cipher_ctx, in_data, len, out_data, len); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | void | 100 | void |
| 101 | QPDFCrypto_gnutls::RC4_finalize() | 101 | QPDFCrypto_gnutls::RC4_finalize() |
| 102 | { | 102 | { |
| 103 | - if (this->cipher_ctx) { | ||
| 104 | - gnutls_cipher_deinit(this->cipher_ctx); | ||
| 105 | - this->cipher_ctx = nullptr; | 103 | + if (cipher_ctx) { |
| 104 | + gnutls_cipher_deinit(cipher_ctx); | ||
| 105 | + cipher_ctx = nullptr; | ||
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| 108 | 108 | ||
| @@ -125,10 +125,10 @@ QPDFCrypto_gnutls::SHA2_init(int bits) | @@ -125,10 +125,10 @@ QPDFCrypto_gnutls::SHA2_init(int bits) | ||
| 125 | badBits(); | 125 | badBits(); |
| 126 | break; | 126 | break; |
| 127 | } | 127 | } |
| 128 | - this->sha2_bits = bits; | ||
| 129 | - int code = gnutls_hash_init(&this->hash_ctx, alg); | 128 | + sha2_bits = bits; |
| 129 | + int code = gnutls_hash_init(&hash_ctx, alg); | ||
| 130 | if (code < 0) { | 130 | if (code < 0) { |
| 131 | - this->hash_ctx = nullptr; | 131 | + hash_ctx = nullptr; |
| 132 | throw std::runtime_error( | 132 | throw std::runtime_error( |
| 133 | std::string("gnutls: SHA") + std::to_string(bits) + | 133 | std::string("gnutls: SHA") + std::to_string(bits) + |
| 134 | " error: " + std::string(gnutls_strerror(code))); | 134 | " error: " + std::string(gnutls_strerror(code))); |
| @@ -138,15 +138,15 @@ QPDFCrypto_gnutls::SHA2_init(int bits) | @@ -138,15 +138,15 @@ QPDFCrypto_gnutls::SHA2_init(int bits) | ||
| 138 | void | 138 | void |
| 139 | QPDFCrypto_gnutls::SHA2_update(unsigned char const* data, size_t len) | 139 | QPDFCrypto_gnutls::SHA2_update(unsigned char const* data, size_t len) |
| 140 | { | 140 | { |
| 141 | - gnutls_hash(this->hash_ctx, data, len); | 141 | + gnutls_hash(hash_ctx, data, len); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | void | 144 | void |
| 145 | QPDFCrypto_gnutls::SHA2_finalize() | 145 | QPDFCrypto_gnutls::SHA2_finalize() |
| 146 | { | 146 | { |
| 147 | - if (this->hash_ctx) { | ||
| 148 | - gnutls_hash_deinit(this->hash_ctx, this->digest); | ||
| 149 | - this->hash_ctx = nullptr; | 147 | + if (hash_ctx) { |
| 148 | + gnutls_hash_deinit(hash_ctx, digest); | ||
| 149 | + hash_ctx = nullptr; | ||
| 150 | } | 150 | } |
| 151 | } | 151 | } |
| 152 | 152 | ||
| @@ -154,15 +154,15 @@ std::string | @@ -154,15 +154,15 @@ std::string | ||
| 154 | QPDFCrypto_gnutls::SHA2_digest() | 154 | QPDFCrypto_gnutls::SHA2_digest() |
| 155 | { | 155 | { |
| 156 | std::string result; | 156 | std::string result; |
| 157 | - switch (this->sha2_bits) { | 157 | + switch (sha2_bits) { |
| 158 | case 256: | 158 | case 256: |
| 159 | - result = std::string(reinterpret_cast<char*>(this->digest), 32); | 159 | + result = std::string(reinterpret_cast<char*>(digest), 32); |
| 160 | break; | 160 | break; |
| 161 | case 384: | 161 | case 384: |
| 162 | - result = std::string(reinterpret_cast<char*>(this->digest), 48); | 162 | + result = std::string(reinterpret_cast<char*>(digest), 48); |
| 163 | break; | 163 | break; |
| 164 | case 512: | 164 | case 512: |
| 165 | - result = std::string(reinterpret_cast<char*>(this->digest), 64); | 165 | + result = std::string(reinterpret_cast<char*>(digest), 64); |
| 166 | break; | 166 | break; |
| 167 | default: | 167 | default: |
| 168 | badBits(); | 168 | badBits(); |
| @@ -184,8 +184,8 @@ QPDFCrypto_gnutls::rijndael_init( | @@ -184,8 +184,8 @@ QPDFCrypto_gnutls::rijndael_init( | ||
| 184 | this->cbc_mode = cbc_mode; | 184 | this->cbc_mode = cbc_mode; |
| 185 | if (!cbc_mode) { | 185 | if (!cbc_mode) { |
| 186 | // Save the key so we can re-initialize. | 186 | // Save the key so we can re-initialize. |
| 187 | - this->aes_key_data = key_data; | ||
| 188 | - this->aes_key_len = key_len; | 187 | + aes_key_data = key_data; |
| 188 | + aes_key_len = key_len; | ||
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | gnutls_cipher_algorithm_t alg = GNUTLS_CIPHER_UNKNOWN; | 191 | gnutls_cipher_algorithm_t alg = GNUTLS_CIPHER_UNKNOWN; |
| @@ -214,9 +214,9 @@ QPDFCrypto_gnutls::rijndael_init( | @@ -214,9 +214,9 @@ QPDFCrypto_gnutls::rijndael_init( | ||
| 214 | iv.data = cbc_block; | 214 | iv.data = cbc_block; |
| 215 | iv.size = rijndael_buf_size; | 215 | iv.size = rijndael_buf_size; |
| 216 | 216 | ||
| 217 | - int code = gnutls_cipher_init(&this->cipher_ctx, alg, &cipher_key, &iv); | 217 | + int code = gnutls_cipher_init(&cipher_ctx, alg, &cipher_key, &iv); |
| 218 | if (code < 0) { | 218 | if (code < 0) { |
| 219 | - this->cipher_ctx = nullptr; | 219 | + cipher_ctx = nullptr; |
| 220 | throw std::runtime_error( | 220 | throw std::runtime_error( |
| 221 | std::string("gnutls: AES error: ") + std::string(gnutls_strerror(code))); | 221 | std::string("gnutls: AES error: ") + std::string(gnutls_strerror(code))); |
| 222 | } | 222 | } |
| @@ -225,29 +225,27 @@ QPDFCrypto_gnutls::rijndael_init( | @@ -225,29 +225,27 @@ QPDFCrypto_gnutls::rijndael_init( | ||
| 225 | void | 225 | void |
| 226 | QPDFCrypto_gnutls::rijndael_process(unsigned char* in_data, unsigned char* out_data) | 226 | QPDFCrypto_gnutls::rijndael_process(unsigned char* in_data, unsigned char* out_data) |
| 227 | { | 227 | { |
| 228 | - if (this->encrypt) { | ||
| 229 | - gnutls_cipher_encrypt2( | ||
| 230 | - this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); | 228 | + if (encrypt) { |
| 229 | + gnutls_cipher_encrypt2(cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); | ||
| 231 | } else { | 230 | } else { |
| 232 | - gnutls_cipher_decrypt2( | ||
| 233 | - this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); | 231 | + gnutls_cipher_decrypt2(cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); |
| 234 | } | 232 | } |
| 235 | 233 | ||
| 236 | // Gnutls doesn't support AES in ECB (non-CBC) mode, but the result is the same as if you just | 234 | // Gnutls doesn't support AES in ECB (non-CBC) mode, but the result is the same as if you just |
| 237 | // reset the cbc block to all zeroes each time. We jump through a few hoops here to make this | 235 | // reset the cbc block to all zeroes each time. We jump through a few hoops here to make this |
| 238 | // work. | 236 | // work. |
| 239 | - if (!this->cbc_mode) { | 237 | + if (!cbc_mode) { |
| 240 | static unsigned char zeroes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | 238 | static unsigned char zeroes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 241 | - rijndael_init(this->encrypt, this->aes_key_data, this->aes_key_len, false, zeroes); | 239 | + rijndael_init(encrypt, aes_key_data, aes_key_len, false, zeroes); |
| 242 | } | 240 | } |
| 243 | } | 241 | } |
| 244 | 242 | ||
| 245 | void | 243 | void |
| 246 | QPDFCrypto_gnutls::rijndael_finalize() | 244 | QPDFCrypto_gnutls::rijndael_finalize() |
| 247 | { | 245 | { |
| 248 | - if (this->cipher_ctx) { | ||
| 249 | - gnutls_cipher_deinit(this->cipher_ctx); | ||
| 250 | - this->cipher_ctx = nullptr; | 246 | + if (cipher_ctx) { |
| 247 | + gnutls_cipher_deinit(cipher_ctx); | ||
| 248 | + cipher_ctx = nullptr; | ||
| 251 | } | 249 | } |
| 252 | } | 250 | } |
| 253 | 251 |
libqpdf/QPDFCrypto_native.cc
| @@ -40,37 +40,37 @@ QPDFCrypto_native::provideRandomData(unsigned char* data, size_t len) | @@ -40,37 +40,37 @@ QPDFCrypto_native::provideRandomData(unsigned char* data, size_t len) | ||
| 40 | void | 40 | void |
| 41 | QPDFCrypto_native::MD5_init() | 41 | QPDFCrypto_native::MD5_init() |
| 42 | { | 42 | { |
| 43 | - this->md5 = std::make_shared<MD5_native>(); | 43 | + md5 = std::make_shared<MD5_native>(); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | void | 46 | void |
| 47 | QPDFCrypto_native::MD5_update(unsigned char const* data, size_t len) | 47 | QPDFCrypto_native::MD5_update(unsigned char const* data, size_t len) |
| 48 | { | 48 | { |
| 49 | - this->md5->update(const_cast<unsigned char*>(data), len); | 49 | + md5->update(const_cast<unsigned char*>(data), len); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | void | 52 | void |
| 53 | QPDFCrypto_native::MD5_finalize() | 53 | QPDFCrypto_native::MD5_finalize() |
| 54 | { | 54 | { |
| 55 | - this->md5->finalize(); | 55 | + md5->finalize(); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | void | 58 | void |
| 59 | QPDFCrypto_native::MD5_digest(MD5_Digest d) | 59 | QPDFCrypto_native::MD5_digest(MD5_Digest d) |
| 60 | { | 60 | { |
| 61 | - this->md5->digest(d); | 61 | + md5->digest(d); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | void | 64 | void |
| 65 | QPDFCrypto_native::RC4_init(unsigned char const* key_data, int key_len) | 65 | QPDFCrypto_native::RC4_init(unsigned char const* key_data, int key_len) |
| 66 | { | 66 | { |
| 67 | - this->rc4 = std::make_shared<RC4_native>(key_data, key_len); | 67 | + rc4 = std::make_shared<RC4_native>(key_data, key_len); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | void | 70 | void |
| 71 | QPDFCrypto_native::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) | 71 | QPDFCrypto_native::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) |
| 72 | { | 72 | { |
| 73 | - this->rc4->process(in_data, len, out_data); | 73 | + rc4->process(in_data, len, out_data); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | void | 76 | void |
| @@ -81,25 +81,25 @@ QPDFCrypto_native::RC4_finalize() | @@ -81,25 +81,25 @@ QPDFCrypto_native::RC4_finalize() | ||
| 81 | void | 81 | void |
| 82 | QPDFCrypto_native::SHA2_init(int bits) | 82 | QPDFCrypto_native::SHA2_init(int bits) |
| 83 | { | 83 | { |
| 84 | - this->sha2 = std::make_shared<SHA2_native>(bits); | 84 | + sha2 = std::make_shared<SHA2_native>(bits); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | void | 87 | void |
| 88 | QPDFCrypto_native::SHA2_update(unsigned char const* data, size_t len) | 88 | QPDFCrypto_native::SHA2_update(unsigned char const* data, size_t len) |
| 89 | { | 89 | { |
| 90 | - this->sha2->update(data, len); | 90 | + sha2->update(data, len); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | void | 93 | void |
| 94 | QPDFCrypto_native::SHA2_finalize() | 94 | QPDFCrypto_native::SHA2_finalize() |
| 95 | { | 95 | { |
| 96 | - this->sha2->finalize(); | 96 | + sha2->finalize(); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | std::string | 99 | std::string |
| 100 | QPDFCrypto_native::SHA2_digest() | 100 | QPDFCrypto_native::SHA2_digest() |
| 101 | { | 101 | { |
| 102 | - return this->sha2->getRawDigest(); | 102 | + return sha2->getRawDigest(); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | void | 105 | void |
| @@ -111,14 +111,13 @@ QPDFCrypto_native::rijndael_init( | @@ -111,14 +111,13 @@ QPDFCrypto_native::rijndael_init( | ||
| 111 | unsigned char* cbc_block) | 111 | unsigned char* cbc_block) |
| 112 | 112 | ||
| 113 | { | 113 | { |
| 114 | - this->aes_pdf = | ||
| 115 | - std::make_shared<AES_PDF_native>(encrypt, key_data, key_len, cbc_mode, cbc_block); | 114 | + aes_pdf = std::make_shared<AES_PDF_native>(encrypt, key_data, key_len, cbc_mode, cbc_block); |
| 116 | } | 115 | } |
| 117 | 116 | ||
| 118 | void | 117 | void |
| 119 | QPDFCrypto_native::rijndael_process(unsigned char* in_data, unsigned char* out_data) | 118 | QPDFCrypto_native::rijndael_process(unsigned char* in_data, unsigned char* out_data) |
| 120 | { | 119 | { |
| 121 | - this->aes_pdf->update(in_data, out_data); | 120 | + aes_pdf->update(in_data, out_data); |
| 122 | } | 121 | } |
| 123 | 122 | ||
| 124 | void | 123 | void |
libqpdf/QPDFCrypto_openssl.cc
| @@ -236,9 +236,7 @@ QPDFCrypto_openssl::rijndael_init( | @@ -236,9 +236,7 @@ QPDFCrypto_openssl::rijndael_init( | ||
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx)); | 238 | check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx)); |
| 239 | - check_openssl( | ||
| 240 | - // line-break | ||
| 241 | - EVP_CipherInit_ex(cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt)); | 239 | + check_openssl(EVP_CipherInit_ex(cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt)); |
| 242 | check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0)); | 240 | check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0)); |
| 243 | } | 241 | } |
| 244 | 242 |
libqpdf/QPDFEmbeddedFileDocumentHelper.cc
| @@ -63,7 +63,7 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() | @@ -63,7 +63,7 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() | ||
| 63 | } | 63 | } |
| 64 | auto embedded_files = names.getKey("/EmbeddedFiles"); | 64 | auto embedded_files = names.getKey("/EmbeddedFiles"); |
| 65 | if (!embedded_files.isDictionary()) { | 65 | if (!embedded_files.isDictionary()) { |
| 66 | - auto nth = QPDFNameTreeObjectHelper::newEmpty(this->qpdf); | 66 | + auto nth = QPDFNameTreeObjectHelper::newEmpty(qpdf); |
| 67 | names.replaceKey("/EmbeddedFiles", nth.getObjectHandle()); | 67 | names.replaceKey("/EmbeddedFiles", nth.getObjectHandle()); |
| 68 | m->embedded_files = std::make_shared<QPDFNameTreeObjectHelper>(nth); | 68 | m->embedded_files = std::make_shared<QPDFNameTreeObjectHelper>(nth); |
| 69 | } | 69 | } |
| @@ -115,7 +115,7 @@ QPDFEmbeddedFileDocumentHelper::removeEmbeddedFile(std::string const& name) | @@ -115,7 +115,7 @@ QPDFEmbeddedFileDocumentHelper::removeEmbeddedFile(std::string const& name) | ||
| 115 | auto oh = iter->second; | 115 | auto oh = iter->second; |
| 116 | iter.remove(); | 116 | iter.remove(); |
| 117 | if (oh.isIndirect()) { | 117 | if (oh.isIndirect()) { |
| 118 | - this->qpdf.replaceObject(oh.getObjGen(), QPDFObjectHandle::newNull()); | 118 | + qpdf.replaceObject(oh.getObjGen(), QPDFObjectHandle::newNull()); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | return true; | 121 | return true; |
libqpdf/QPDFFormFieldObjectHelper.cc
| @@ -655,15 +655,76 @@ ValueSetter::writeAppearance() | @@ -655,15 +655,76 @@ ValueSetter::writeAppearance() | ||
| 655 | 655 | ||
| 656 | namespace | 656 | namespace |
| 657 | { | 657 | { |
| 658 | - class TfFinder: public QPDFObjectHandle::TokenFilter | 658 | + class TfFinder final: public QPDFObjectHandle::TokenFilter |
| 659 | { | 659 | { |
| 660 | public: | 660 | public: |
| 661 | TfFinder() = default; | 661 | TfFinder() = default; |
| 662 | - ~TfFinder() override = default; | ||
| 663 | - void handleToken(QPDFTokenizer::Token const&) override; | ||
| 664 | - double getTf(); | ||
| 665 | - std::string getFontName(); | ||
| 666 | - std::string getDA(); | 662 | + ~TfFinder() final = default; |
| 663 | + | ||
| 664 | + void | ||
| 665 | + handleToken(QPDFTokenizer::Token const& token) final | ||
| 666 | + { | ||
| 667 | + auto ttype = token.getType(); | ||
| 668 | + auto const& value = token.getValue(); | ||
| 669 | + DA.emplace_back(token.getRawValue()); | ||
| 670 | + switch (ttype) { | ||
| 671 | + case QPDFTokenizer::tt_integer: | ||
| 672 | + case QPDFTokenizer::tt_real: | ||
| 673 | + last_num = strtod(value.c_str(), nullptr); | ||
| 674 | + last_num_idx = QIntC::to_int(DA.size() - 1); | ||
| 675 | + break; | ||
| 676 | + | ||
| 677 | + case QPDFTokenizer::tt_name: | ||
| 678 | + last_name = value; | ||
| 679 | + break; | ||
| 680 | + | ||
| 681 | + case QPDFTokenizer::tt_word: | ||
| 682 | + if (token.isWord("Tf")) { | ||
| 683 | + if ((last_num > 1.0) && (last_num < 1000.0)) { | ||
| 684 | + // These ranges are arbitrary but keep us from doing insane things or | ||
| 685 | + // suffering from over/underflow | ||
| 686 | + tf = last_num; | ||
| 687 | + } | ||
| 688 | + tf_idx = last_num_idx; | ||
| 689 | + font_name = last_name; | ||
| 690 | + } | ||
| 691 | + break; | ||
| 692 | + | ||
| 693 | + default: | ||
| 694 | + break; | ||
| 695 | + } | ||
| 696 | + } | ||
| 697 | + | ||
| 698 | + double | ||
| 699 | + getTf() const | ||
| 700 | + { | ||
| 701 | + return tf; | ||
| 702 | + } | ||
| 703 | + std::string | ||
| 704 | + getFontName() const | ||
| 705 | + { | ||
| 706 | + return font_name; | ||
| 707 | + } | ||
| 708 | + | ||
| 709 | + std::string | ||
| 710 | + getDA() | ||
| 711 | + { | ||
| 712 | + std::string result; | ||
| 713 | + int i = -1; | ||
| 714 | + for (auto const& cur: DA) { | ||
| 715 | + if (++i == tf_idx) { | ||
| 716 | + double delta = strtod(cur.c_str(), nullptr) - tf; | ||
| 717 | + if (delta > 0.001 || delta < -0.001) { | ||
| 718 | + // tf doesn't match the font size passed to Tf, so substitute. | ||
| 719 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper fallback Tf"); | ||
| 720 | + result += QUtil::double_to_string(tf); | ||
| 721 | + continue; | ||
| 722 | + } | ||
| 723 | + } | ||
| 724 | + result += cur; | ||
| 725 | + } | ||
| 726 | + return result; | ||
| 727 | + } | ||
| 667 | 728 | ||
| 668 | private: | 729 | private: |
| 669 | double tf{11.0}; | 730 | double tf{11.0}; |
| @@ -676,72 +737,6 @@ namespace | @@ -676,72 +737,6 @@ namespace | ||
| 676 | }; | 737 | }; |
| 677 | } // namespace | 738 | } // namespace |
| 678 | 739 | ||
| 679 | -void | ||
| 680 | -TfFinder::handleToken(QPDFTokenizer::Token const& token) | ||
| 681 | -{ | ||
| 682 | - QPDFTokenizer::token_type_e ttype = token.getType(); | ||
| 683 | - std::string value = token.getValue(); | ||
| 684 | - DA.push_back(token.getRawValue()); | ||
| 685 | - switch (ttype) { | ||
| 686 | - case QPDFTokenizer::tt_integer: | ||
| 687 | - case QPDFTokenizer::tt_real: | ||
| 688 | - last_num = strtod(value.c_str(), nullptr); | ||
| 689 | - last_num_idx = QIntC::to_int(DA.size() - 1); | ||
| 690 | - break; | ||
| 691 | - | ||
| 692 | - case QPDFTokenizer::tt_name: | ||
| 693 | - last_name = value; | ||
| 694 | - break; | ||
| 695 | - | ||
| 696 | - case QPDFTokenizer::tt_word: | ||
| 697 | - if (token.isWord("Tf")) { | ||
| 698 | - if ((last_num > 1.0) && (last_num < 1000.0)) { | ||
| 699 | - // These ranges are arbitrary but keep us from doing insane things or suffering from | ||
| 700 | - // over/underflow | ||
| 701 | - tf = last_num; | ||
| 702 | - } | ||
| 703 | - tf_idx = last_num_idx; | ||
| 704 | - font_name = last_name; | ||
| 705 | - } | ||
| 706 | - break; | ||
| 707 | - | ||
| 708 | - default: | ||
| 709 | - break; | ||
| 710 | - } | ||
| 711 | -} | ||
| 712 | - | ||
| 713 | -double | ||
| 714 | -TfFinder::getTf() | ||
| 715 | -{ | ||
| 716 | - return tf; | ||
| 717 | -} | ||
| 718 | - | ||
| 719 | -std::string | ||
| 720 | -TfFinder::getDA() | ||
| 721 | -{ | ||
| 722 | - std::string result; | ||
| 723 | - size_t n = DA.size(); | ||
| 724 | - for (size_t i = 0; i < n; ++i) { | ||
| 725 | - std::string cur = DA.at(i); | ||
| 726 | - if (QIntC::to_int(i) == tf_idx) { | ||
| 727 | - double delta = strtod(cur.c_str(), nullptr) - tf; | ||
| 728 | - if ((delta > 0.001) || (delta < -0.001)) { | ||
| 729 | - // tf doesn't match the font size passed to Tf, so substitute. | ||
| 730 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper fallback Tf"); | ||
| 731 | - cur = QUtil::double_to_string(tf); | ||
| 732 | - } | ||
| 733 | - } | ||
| 734 | - result += cur; | ||
| 735 | - } | ||
| 736 | - return result; | ||
| 737 | -} | ||
| 738 | - | ||
| 739 | -std::string | ||
| 740 | -TfFinder::getFontName() | ||
| 741 | -{ | ||
| 742 | - return font_name; | ||
| 743 | -} | ||
| 744 | - | ||
| 745 | QPDFObjectHandle | 740 | QPDFObjectHandle |
| 746 | QPDFFormFieldObjectHelper::getFontFromResource(QPDFObjectHandle resources, std::string const& name) | 741 | QPDFFormFieldObjectHelper::getFontFromResource(QPDFObjectHandle resources, std::string const& name) |
| 747 | { | 742 | { |
libqpdf/QPDFNameTreeObjectHelper.cc
| @@ -89,11 +89,11 @@ QPDFNameTreeObjectHelper::iterator::updateIValue() | @@ -89,11 +89,11 @@ QPDFNameTreeObjectHelper::iterator::updateIValue() | ||
| 89 | { | 89 | { |
| 90 | if (impl->valid()) { | 90 | if (impl->valid()) { |
| 91 | auto p = *impl; | 91 | auto p = *impl; |
| 92 | - this->ivalue.first = p->first.getUTF8Value(); | ||
| 93 | - this->ivalue.second = p->second; | 92 | + ivalue.first = p->first.getUTF8Value(); |
| 93 | + ivalue.second = p->second; | ||
| 94 | } else { | 94 | } else { |
| 95 | - this->ivalue.first = ""; | ||
| 96 | - this->ivalue.second = QPDFObjectHandle(); | 95 | + ivalue.first = ""; |
| 96 | + ivalue.second = QPDFObjectHandle(); | ||
| 97 | } | 97 | } |
| 98 | } | 98 | } |
| 99 | 99 | ||
| @@ -101,14 +101,14 @@ QPDFNameTreeObjectHelper::iterator::reference | @@ -101,14 +101,14 @@ QPDFNameTreeObjectHelper::iterator::reference | ||
| 101 | QPDFNameTreeObjectHelper::iterator::operator*() | 101 | QPDFNameTreeObjectHelper::iterator::operator*() |
| 102 | { | 102 | { |
| 103 | updateIValue(); | 103 | updateIValue(); |
| 104 | - return this->ivalue; | 104 | + return ivalue; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | QPDFNameTreeObjectHelper::iterator::pointer | 107 | QPDFNameTreeObjectHelper::iterator::pointer |
| 108 | QPDFNameTreeObjectHelper::iterator::operator->() | 108 | QPDFNameTreeObjectHelper::iterator::operator->() |
| 109 | { | 109 | { |
| 110 | updateIValue(); | 110 | updateIValue(); |
| 111 | - return &this->ivalue; | 111 | + return &ivalue; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | bool | 114 | bool |
libqpdf/QPDFObjectHandle.cc
| 1 | +#include <qpdf/assert_debug.h> | ||
| 2 | + | ||
| 1 | #include <qpdf/QPDFObjectHandle_private.hh> | 3 | #include <qpdf/QPDFObjectHandle_private.hh> |
| 2 | 4 | ||
| 3 | -#include <qpdf/BufferInputSource.hh> | 5 | +#include <qpdf/InputSource_private.hh> |
| 4 | #include <qpdf/JSON_writer.hh> | 6 | #include <qpdf/JSON_writer.hh> |
| 7 | +#include <qpdf/Pipeline_private.hh> | ||
| 5 | #include <qpdf/Pl_Buffer.hh> | 8 | #include <qpdf/Pl_Buffer.hh> |
| 6 | #include <qpdf/Pl_QPDFTokenizer.hh> | 9 | #include <qpdf/Pl_QPDFTokenizer.hh> |
| 10 | +#include <qpdf/QIntC.hh> | ||
| 7 | #include <qpdf/QPDF.hh> | 11 | #include <qpdf/QPDF.hh> |
| 8 | #include <qpdf/QPDFExc.hh> | 12 | #include <qpdf/QPDFExc.hh> |
| 9 | #include <qpdf/QPDFLogger.hh> | 13 | #include <qpdf/QPDFLogger.hh> |
| @@ -11,13 +15,9 @@ | @@ -11,13 +15,9 @@ | ||
| 11 | #include <qpdf/QPDFObject_private.hh> | 15 | #include <qpdf/QPDFObject_private.hh> |
| 12 | #include <qpdf/QPDFPageObjectHelper.hh> | 16 | #include <qpdf/QPDFPageObjectHelper.hh> |
| 13 | #include <qpdf/QPDFParser.hh> | 17 | #include <qpdf/QPDFParser.hh> |
| 14 | - | ||
| 15 | -#include <qpdf/QIntC.hh> | ||
| 16 | #include <qpdf/QTC.hh> | 18 | #include <qpdf/QTC.hh> |
| 17 | -#include <qpdf/QUtil.hh> | ||
| 18 | #include <qpdf/Util.hh> | 19 | #include <qpdf/Util.hh> |
| 19 | 20 | ||
| 20 | -#include <algorithm> | ||
| 21 | #include <array> | 21 | #include <array> |
| 22 | #include <cctype> | 22 | #include <cctype> |
| 23 | #include <climits> | 23 | #include <climits> |
| @@ -174,48 +174,6 @@ QPDFObjectHandle::ParserCallbacks::terminateParsing() | @@ -174,48 +174,6 @@ QPDFObjectHandle::ParserCallbacks::terminateParsing() | ||
| 174 | throw TerminateParsing(); | 174 | throw TerminateParsing(); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | -namespace | ||
| 178 | -{ | ||
| 179 | - class LastChar final: public Pipeline | ||
| 180 | - { | ||
| 181 | - public: | ||
| 182 | - LastChar(Pipeline& next); | ||
| 183 | - ~LastChar() final = default; | ||
| 184 | - void write(unsigned char const* data, size_t len) final; | ||
| 185 | - void finish() final; | ||
| 186 | - unsigned char getLastChar(); | ||
| 187 | - | ||
| 188 | - private: | ||
| 189 | - unsigned char last_char{0}; | ||
| 190 | - }; | ||
| 191 | -} // namespace | ||
| 192 | - | ||
| 193 | -LastChar::LastChar(Pipeline& next) : | ||
| 194 | - Pipeline("lastchar", &next) | ||
| 195 | -{ | ||
| 196 | -} | ||
| 197 | - | ||
| 198 | -void | ||
| 199 | -LastChar::write(unsigned char const* data, size_t len) | ||
| 200 | -{ | ||
| 201 | - if (len > 0) { | ||
| 202 | - last_char = data[len - 1]; | ||
| 203 | - } | ||
| 204 | - next()->write(data, len); | ||
| 205 | -} | ||
| 206 | - | ||
| 207 | -void | ||
| 208 | -LastChar::finish() | ||
| 209 | -{ | ||
| 210 | - next()->finish(); | ||
| 211 | -} | ||
| 212 | - | ||
| 213 | -unsigned char | ||
| 214 | -LastChar::getLastChar() | ||
| 215 | -{ | ||
| 216 | - return last_char; | ||
| 217 | -} | ||
| 218 | - | ||
| 219 | std::pair<bool, bool> | 177 | std::pair<bool, bool> |
| 220 | Name::analyzeJSONEncoding(const std::string& name) | 178 | Name::analyzeJSONEncoding(const std::string& name) |
| 221 | { | 179 | { |
| @@ -1527,16 +1485,14 @@ void | @@ -1527,16 +1485,14 @@ void | ||
| 1527 | QPDFObjectHandle::pipeContentStreams( | 1485 | QPDFObjectHandle::pipeContentStreams( |
| 1528 | Pipeline* p, std::string const& description, std::string& all_description) | 1486 | Pipeline* p, std::string const& description, std::string& all_description) |
| 1529 | { | 1487 | { |
| 1530 | - std::vector<QPDFObjectHandle> streams = | ||
| 1531 | - arrayOrStreamToStreamArray(description, all_description); | ||
| 1532 | bool need_newline = false; | 1488 | bool need_newline = false; |
| 1533 | - Pl_Buffer buf("concatenated content stream buffer"); | ||
| 1534 | - for (auto stream: streams) { | 1489 | + std::string buffer; |
| 1490 | + pl::String buf(buffer); | ||
| 1491 | + for (auto stream: arrayOrStreamToStreamArray(description, all_description)) { | ||
| 1535 | if (need_newline) { | 1492 | if (need_newline) { |
| 1536 | buf.writeCStr("\n"); | 1493 | buf.writeCStr("\n"); |
| 1537 | } | 1494 | } |
| 1538 | - LastChar lc(buf); | ||
| 1539 | - if (!stream.pipeStreamData(&lc, 0, qpdf_dl_specialized)) { | 1495 | + if (!stream.pipeStreamData(&buf, 0, qpdf_dl_specialized)) { |
| 1540 | QTC::TC("qpdf", "QPDFObjectHandle errors in parsecontent"); | 1496 | QTC::TC("qpdf", "QPDFObjectHandle errors in parsecontent"); |
| 1541 | throw QPDFExc( | 1497 | throw QPDFExc( |
| 1542 | qpdf_e_damaged_pdf, | 1498 | qpdf_e_damaged_pdf, |
| @@ -1545,11 +1501,11 @@ QPDFObjectHandle::pipeContentStreams( | @@ -1545,11 +1501,11 @@ QPDFObjectHandle::pipeContentStreams( | ||
| 1545 | 0, | 1501 | 0, |
| 1546 | "errors while decoding content stream"); | 1502 | "errors while decoding content stream"); |
| 1547 | } | 1503 | } |
| 1548 | - lc.finish(); | ||
| 1549 | - need_newline = (lc.getLastChar() != static_cast<unsigned char>('\n')); | 1504 | + need_newline = buffer.empty() || buffer.back() != '\n'; |
| 1550 | QTC::TC("qpdf", "QPDFObjectHandle need_newline", need_newline ? 0 : 1); | 1505 | QTC::TC("qpdf", "QPDFObjectHandle need_newline", need_newline ? 0 : 1); |
| 1506 | + p->writeString(buffer); | ||
| 1507 | + buffer.clear(); | ||
| 1551 | } | 1508 | } |
| 1552 | - p->writeString(buf.getString()); | ||
| 1553 | p->finish(); | 1509 | p->finish(); |
| 1554 | } | 1510 | } |
| 1555 | 1511 |
libqpdf/QPDF_objects.cc
| @@ -1169,8 +1169,8 @@ QPDFObjectHandle | @@ -1169,8 +1169,8 @@ QPDFObjectHandle | ||
| 1169 | QPDF::readTrailer() | 1169 | QPDF::readTrailer() |
| 1170 | { | 1170 | { |
| 1171 | qpdf_offset_t offset = m->file->tell(); | 1171 | qpdf_offset_t offset = m->file->tell(); |
| 1172 | - auto [object, empty] = QPDFParser::parse( | ||
| 1173 | - *m->file, "trailer", m->tokenizer, nullptr, *this, m->reconstructed_xref); | 1172 | + auto [object, empty] = |
| 1173 | + QPDFParser::parse(*m->file, "trailer", m->tokenizer, nullptr, *this, m->reconstructed_xref); | ||
| 1174 | if (empty) { | 1174 | if (empty) { |
| 1175 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in | 1175 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in |
| 1176 | // actual PDF files and Adobe Reader appears to ignore them. | 1176 | // actual PDF files and Adobe Reader appears to ignore them. |
libqpdf/RC4.cc
| @@ -5,11 +5,11 @@ | @@ -5,11 +5,11 @@ | ||
| 5 | RC4::RC4(unsigned char const* key_data, int key_len) : | 5 | RC4::RC4(unsigned char const* key_data, int key_len) : |
| 6 | crypto(QPDFCryptoProvider::getImpl()) | 6 | crypto(QPDFCryptoProvider::getImpl()) |
| 7 | { | 7 | { |
| 8 | - this->crypto->RC4_init(key_data, key_len); | 8 | + crypto->RC4_init(key_data, key_len); |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | void | 11 | void |
| 12 | RC4::process(unsigned char const* in_data, size_t len, unsigned char* out_data) | 12 | RC4::process(unsigned char const* in_data, size_t len, unsigned char* out_data) |
| 13 | { | 13 | { |
| 14 | - this->crypto->RC4_process(in_data, len, out_data); | 14 | + crypto->RC4_process(in_data, len, out_data); |
| 15 | } | 15 | } |
libqpdf/qpdf/Pipeline_private.hh
libqpdf/qpdf/QPDFCrypto_native.hh
| @@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
| 6 | #include <qpdf/QPDFCryptoImpl.hh> | 6 | #include <qpdf/QPDFCryptoImpl.hh> |
| 7 | #include <qpdf/RC4_native.hh> | 7 | #include <qpdf/RC4_native.hh> |
| 8 | #include <qpdf/SHA2_native.hh> | 8 | #include <qpdf/SHA2_native.hh> |
| 9 | + | ||
| 9 | #include <memory> | 10 | #include <memory> |
| 10 | 11 | ||
| 11 | class QPDFCrypto_native final: public QPDFCryptoImpl | 12 | class QPDFCrypto_native final: public QPDFCryptoImpl |