Skip to content
forked from qpdf/qpdf

Commit

Permalink
Move calculations from QPDF::getObjectCount to Objects::next_id
Browse files Browse the repository at this point in the history
  • Loading branch information
m-holger committed Oct 9, 2024
1 parent 113ea4e commit 336d783
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/qpdf/QPDF.hh
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class QPDF
QPDF_DLL
void fixDanglingReferences(bool force = false);

// Return the approximate number of indirect objects. It is/ approximate because not all objects
// Return the approximate number of indirect objects. It is approximate because not all objects
// in the file are preserved in all cases, and gaps in object numbering are not preserved.
QPDF_DLL
size_t getObjectCount();
Expand Down
7 changes: 1 addition & 6 deletions libqpdf/QPDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,7 @@ QPDF::getObjectCount()
// This method returns the next available indirect object number. makeIndirectObject uses it for
// this purpose. After fixDanglingReferences is called, all objects in the xref table will also
// be in obj_cache.
fixDanglingReferences();
QPDFObjGen og;
if (!m->objects.obj_cache.empty()) {
og = (*(m->objects.obj_cache.rbegin())).first;
}
return toS(og.getObj());
return toS(m->objects.next_id().getObj() - 1);
}

std::vector<QPDFObjectHandle>
Expand Down
7 changes: 6 additions & 1 deletion libqpdf/QPDF_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,12 @@ Objects::unresolved(QPDFObjGen og)
QPDFObjGen
Objects::next_id()
{
int max_objid = toI(qpdf.getObjectCount());
qpdf.fixDanglingReferences();
QPDFObjGen og;
if (!obj_cache.empty()) {
og = (*(m->objects.obj_cache.rbegin())).first;
}
int max_objid = og.getObj();
if (max_objid == std::numeric_limits<int>::max()) {
throw std::range_error("max object id is too high to create new objects");
}
Expand Down

0 comments on commit 336d783

Please sign in to comment.