2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-21 10:29:08 +00:00

Move calculations from QPDF::getObjectCount to Objects::next_id

This commit is contained in:
m-holger 2024-10-07 17:57:06 +01:00
parent 113ea4e7ae
commit 336d783325
3 changed files with 8 additions and 8 deletions

View File

@ -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();

View File

@ -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>

View File

@ -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");
}