Commit 336d7833250b9d8d8a28a6f232f659b765925593
1 parent
113ea4e7
Move calculations from QPDF::getObjectCount to Objects::next_id
Showing
3 changed files
with
8 additions
and
8 deletions
include/qpdf/QPDF.hh
| @@ -645,7 +645,7 @@ class QPDF | @@ -645,7 +645,7 @@ class QPDF | ||
| 645 | QPDF_DLL | 645 | QPDF_DLL |
| 646 | void fixDanglingReferences(bool force = false); | 646 | void fixDanglingReferences(bool force = false); |
| 647 | 647 | ||
| 648 | - // Return the approximate number of indirect objects. It is/ approximate because not all objects | 648 | + // Return the approximate number of indirect objects. It is approximate because not all objects |
| 649 | // in the file are preserved in all cases, and gaps in object numbering are not preserved. | 649 | // in the file are preserved in all cases, and gaps in object numbering are not preserved. |
| 650 | QPDF_DLL | 650 | QPDF_DLL |
| 651 | size_t getObjectCount(); | 651 | size_t getObjectCount(); |
libqpdf/QPDF.cc
| @@ -492,12 +492,7 @@ QPDF::getObjectCount() | @@ -492,12 +492,7 @@ QPDF::getObjectCount() | ||
| 492 | // This method returns the next available indirect object number. makeIndirectObject uses it for | 492 | // This method returns the next available indirect object number. makeIndirectObject uses it for |
| 493 | // this purpose. After fixDanglingReferences is called, all objects in the xref table will also | 493 | // this purpose. After fixDanglingReferences is called, all objects in the xref table will also |
| 494 | // be in obj_cache. | 494 | // be in obj_cache. |
| 495 | - fixDanglingReferences(); | ||
| 496 | - QPDFObjGen og; | ||
| 497 | - if (!m->objects.obj_cache.empty()) { | ||
| 498 | - og = (*(m->objects.obj_cache.rbegin())).first; | ||
| 499 | - } | ||
| 500 | - return toS(og.getObj()); | 495 | + return toS(m->objects.next_id().getObj() - 1); |
| 501 | } | 496 | } |
| 502 | 497 | ||
| 503 | std::vector<QPDFObjectHandle> | 498 | std::vector<QPDFObjectHandle> |
libqpdf/QPDF_objects.cc
| @@ -1712,7 +1712,12 @@ Objects::unresolved(QPDFObjGen og) | @@ -1712,7 +1712,12 @@ Objects::unresolved(QPDFObjGen og) | ||
| 1712 | QPDFObjGen | 1712 | QPDFObjGen |
| 1713 | Objects::next_id() | 1713 | Objects::next_id() |
| 1714 | { | 1714 | { |
| 1715 | - int max_objid = toI(qpdf.getObjectCount()); | 1715 | + qpdf.fixDanglingReferences(); |
| 1716 | + QPDFObjGen og; | ||
| 1717 | + if (!obj_cache.empty()) { | ||
| 1718 | + og = (*(m->objects.obj_cache.rbegin())).first; | ||
| 1719 | + } | ||
| 1720 | + int max_objid = og.getObj(); | ||
| 1716 | if (max_objid == std::numeric_limits<int>::max()) { | 1721 | if (max_objid == std::numeric_limits<int>::max()) { |
| 1717 | throw std::range_error("max object id is too high to create new objects"); | 1722 | throw std::range_error("max object id is too high to create new objects"); |
| 1718 | } | 1723 | } |