Commit 3b87d569cba91cfbaefa1e1a1aa1e5ae97bede9b
1 parent
f110a23c
Refactor `NNTreeIterator::insertAfter`: use `const` references for parameters, r…
…eplace `getArrayNItems` with `size`, and improve error handling logic.
Showing
2 changed files
with
7 additions
and
6 deletions
libqpdf/NNTree.cc
| ... | ... | @@ -390,7 +390,7 @@ NNTreeIterator::lastPathElement() |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | void |
| 393 | -NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value) | |
| 393 | +NNTreeIterator::insertAfter(QPDFObjectHandle const& key, QPDFObjectHandle const& value) | |
| 394 | 394 | { |
| 395 | 395 | if (!valid()) { |
| 396 | 396 | QTC::TC("qpdf", "NNTree insertAfter inserts first"); |
| ... | ... | @@ -400,10 +400,11 @@ NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value) |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | auto items = node.getKey(impl.details.itemsKey()); |
| 403 | - if (!items.isArray()) { | |
| 404 | - impl.error(node, "node contains no items array"); | |
| 405 | - } | |
| 406 | - if (items.getArrayNItems() < item_number + 2) { | |
| 403 | + | |
| 404 | + if (std::cmp_less(items.size(), item_number + 2)) { | |
| 405 | + if (!items.isArray()) { | |
| 406 | + impl.error(node, "node contains no items array"); | |
| 407 | + } | |
| 407 | 408 | impl.error(node, "insert: items array is too short"); |
| 408 | 409 | } |
| 409 | 410 | items.insertItem(item_number + 2, key); | ... | ... |
libqpdf/qpdf/NNTree.hh