[poppler] poppler/Annot.cc poppler/AnnotStampImageHelper.cc poppler/Catalog.cc poppler/FileSpec.cc poppler/Form.cc poppler/Outline.cc poppler/Page.cc poppler/PDFDoc.cc poppler/XRef.cc poppler/XRef.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Nov 22 16:14:12 UTC 2021


 poppler/Annot.cc                 |    8 ++++----
 poppler/AnnotStampImageHelper.cc |    3 ++-
 poppler/Catalog.cc               |    9 ++++-----
 poppler/FileSpec.cc              |    5 ++---
 poppler/Form.cc                  |    2 +-
 poppler/Outline.cc               |    4 ++--
 poppler/PDFDoc.cc                |    2 +-
 poppler/Page.cc                  |    6 +++---
 poppler/XRef.cc                  |    9 ++++-----
 poppler/XRef.h                   |    2 +-
 10 files changed, 24 insertions(+), 26 deletions(-)

New commits:
commit 14aca8b62d197db6bcbc92faf7f398ac9a598011
Author: Albert Astals Cid <aacid at kde.org>
Date:   Mon Nov 22 17:04:55 2021 +0100

    XRef::addIndirectObject: Change param from const * to const &
    
    Makes it harder to do mistakes when using it

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 6d1a2aea..f3f6a8e0 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1206,7 +1206,7 @@ Annot::Annot(PDFDoc *docA, PDFRectangle *rectA)
     annotObj.dictSet("Type", Object(objName, "Annot"));
     annotObj.dictSet("Rect", Object(a));
 
-    ref = docA->getXRef()->addIndirectObject(&annotObj);
+    ref = docA->getXRef()->addIndirectObject(annotObj);
 
     initialize(docA, annotObj.getDict());
 }
@@ -1983,7 +1983,7 @@ void Annot::setNewAppearance(Object &&newAppearance)
         invalidateAppearance();
         appearance = std::move(newAppearance);
 
-        Ref updatedAppearanceStream = doc->getXRef()->addIndirectObject(&appearance);
+        Ref updatedAppearanceStream = doc->getXRef()->addIndirectObject(appearance);
 
         Object obj1 = Object(new Dict(doc->getXRef()));
         obj1.dictAdd("N", Object(updatedAppearanceStream));
@@ -5177,7 +5177,7 @@ void AnnotWidget::updateAppearanceStream()
     // Otherwise, just update the stream we had created previously.
     if (updatedAppearanceStream == Ref::INVALID()) {
         // Write the appearance stream
-        updatedAppearanceStream = doc->getXRef()->addIndirectObject(&obj1);
+        updatedAppearanceStream = doc->getXRef()->addIndirectObject(obj1);
 
         // Write the AP dictionary
         obj1 = Object(new Dict(doc->getXRef()));
@@ -5596,7 +5596,7 @@ void AnnotStamp::setCustomImage(AnnotStampImageHelper *stampImageHelperA)
     generateStampCustomAppearance();
 
     if (updatedAppearanceStream == Ref::INVALID()) {
-        updatedAppearanceStream = doc->getXRef()->addIndirectObject(&appearance);
+        updatedAppearanceStream = doc->getXRef()->addIndirectObject(appearance);
     } else {
         Object obj1 = appearance.fetch(doc->getXRef());
         doc->getXRef()->setModifiedObject(&obj1, updatedAppearanceStream);
diff --git a/poppler/AnnotStampImageHelper.cc b/poppler/AnnotStampImageHelper.cc
index d761f9d8..4a345283 100644
--- a/poppler/AnnotStampImageHelper.cc
+++ b/poppler/AnnotStampImageHelper.cc
@@ -3,6 +3,7 @@
 // AnnotStampImageHelper.cc
 //
 // Copyright (C) 2021 Mahmoud Ahmed Khalil <mahmoudkhalil11 at gmail.com>
+// Copyright (C) 2021 Albert Astals Cid <aacid at kde.org>
 //
 // Licensed under GPLv2 or later
 //
@@ -65,7 +66,7 @@ void AnnotStampImageHelper::initialize(PDFDoc *docA, int widthA, int heightA, Co
 
     Stream *dataStream = new AutoFreeMemStream(dataCopied, 0, dataLength, Object(dict));
     imgObj = Object(dataStream);
-    ref = doc->getXRef()->addIndirectObject(&imgObj);
+    ref = doc->getXRef()->addIndirectObject(imgObj);
 }
 
 void AnnotStampImageHelper::removeAnnotStampImageObject()
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 29e93b5b..20cfa8d9 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -463,8 +463,7 @@ void Catalog::addEmbeddedFile(GooFile *file, const std::string &fileName)
 {
     catalogLocker();
 
-    Object fileSpecObj = FileSpec::newFileSpecObject(xref, file, fileName);
-    const Ref fileSpecRef = xref->addIndirectObject(&fileSpecObj);
+    const Ref fileSpecRef = xref->addIndirectObject(FileSpec::newFileSpecObject(xref, file, fileName));
 
     Object catDict = xref->getCatalog();
     Ref namesObjRef;
@@ -482,7 +481,7 @@ void Catalog::addEmbeddedFile(GooFile *file, const std::string &fileName)
 
     // We create a new EmbeddedFiles nametree, this replaces the existing one (if any), but it's not a problem
     Object embeddedFilesObj = Object(new Dict(xref));
-    const Ref embeddedFilesRef = xref->addIndirectObject(&embeddedFilesObj);
+    const Ref embeddedFilesRef = xref->addIndirectObject(embeddedFilesObj);
 
     Array *embeddedFilesNamesArray = new Array(xref);
 
@@ -981,7 +980,7 @@ Object *Catalog::getCreateOutline()
     outline.dictSet("Type", Object(objName, "Outlines"));
     outline.dictSet("Count", Object(0));
 
-    const Ref outlineRef = doc->getXRef()->addIndirectObject(&outline);
+    const Ref outlineRef = doc->getXRef()->addIndirectObject(outline);
     catDict.dictAdd("Outlines", Object(outlineRef));
     xref->setModifiedObject(&catDict, { xref->getRootNum(), xref->getRootGen() });
 
@@ -1068,7 +1067,7 @@ void Catalog::addFormToAcroForm(const Ref formRef)
         fieldArray->add(Object(formRef));
         newForm.dictSet("Fields", Object(fieldArray));
 
-        Ref newRef = xref->addIndirectObject(&newForm);
+        Ref newRef = xref->addIndirectObject(newForm);
         catDict.dictSet("AcroForm", Object(newRef));
         acroForm = catDict.getDict()->lookup("AcroForm");
     } else {
diff --git a/poppler/FileSpec.cc b/poppler/FileSpec.cc
index 53f9384c..590f9291 100644
--- a/poppler/FileSpec.cc
+++ b/poppler/FileSpec.cc
@@ -7,7 +7,7 @@
 //
 // Copyright (C) 2008-2009 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
-// Copyright (C) 2012, 2017-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2012, 2017-2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2012 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
 // Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
@@ -181,8 +181,7 @@ Object FileSpec::newFileSpecObject(XRef *xref, GooFile *file, const std::string
     FileStream *fStream = new FileStream(file, 0, false, file->size(), std::move(streamDict));
     fStream->setNeedsEncryptionOnSave(true);
     Stream *stream = fStream;
-    Object streamObj = Object(stream);
-    const Ref streamRef = xref->addIndirectObject(&streamObj);
+    const Ref streamRef = xref->addIndirectObject(Object(stream));
 
     Dict *efDict = new Dict(xref);
     efDict->set("F", Object(streamRef));
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 46ed2cc9..9bef701c 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -596,7 +596,7 @@ bool FormWidgetSignature::signDocument(const char *saveFilename, const char *cer
     updateWidgetAppearance(); // add visible signing info to appearance
 
     Object vObj(new Dict(xref));
-    Ref vref = xref->addIndirectObject(&vObj);
+    Ref vref = xref->addIndirectObject(vObj);
     if (!createSignature(vObj, vref, GooString(signerName), tmpSignature.get(), reason, location)) {
         return false;
     }
diff --git a/poppler/Outline.cc b/poppler/Outline.cc
index 268dcaf3..74c72d67 100644
--- a/poppler/Outline.cc
+++ b/poppler/Outline.cc
@@ -105,7 +105,7 @@ static void insertChildHelper(const std::string &itemTitle, int destPageNum, uns
     Object prevItemObject;
     Object nextItemObject;
 
-    Ref outlineItemRef = xref->addIndirectObject(&outlineItem);
+    Ref outlineItemRef = xref->addIndirectObject(outlineItem);
 
     // the next two statements fix up the parent object
     // for clarity we separate this out
@@ -294,7 +294,7 @@ int Outline::addOutlineTreeNodeList(const std::vector<OutlineTreeNode> &nodeList
         a->add(Object(objName, "Fit"));
 
         Object outlineItem = Object(new Dict(doc->getXRef()));
-        Ref outlineItemRef = doc->getXRef()->addIndirectObject(&outlineItem);
+        Ref outlineItemRef = doc->getXRef()->addIndirectObject(outlineItem);
 
         if (firstRef == Ref::INVALID()) {
             firstRef = outlineItemRef;
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index e75d6405..ea8e391d 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -2159,7 +2159,7 @@ bool PDFDoc::sign(const char *saveFilename, const char *certNickname, const char
     GooString *daStr = da.toAppearanceString();
     annotObj.dictSet("DA", Object(daStr));
 
-    const Ref ref = getXRef()->addIndirectObject(&annotObj);
+    const Ref ref = getXRef()->addIndirectObject(annotObj);
     catalog->addFormToAcroForm(ref);
 
     std::unique_ptr<::FormFieldSignature> field = std::make_unique<::FormFieldSignature>(this, Object(annotObj.getDict()), ref, nullptr, nullptr);
diff --git a/poppler/Page.cc b/poppler/Page.cc
index ae77d45b..33da9049 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -431,10 +431,10 @@ void Page::addAnnot(Annot *annot)
         // page doesn't have annots array,
         // we have to create it
 
-        Object obj1 = Object(new Array(xref));
-        obj1.arrayAdd(Object(annotRef));
+        Array *annotsArray = new Array(xref);
+        annotsArray->add(Object(annotRef));
 
-        annotsRef = xref->addIndirectObject(&obj1);
+        annotsRef = xref->addIndirectObject(Object(annotsArray));
         annotsObj = Object(annotsRef);
         pageObj.dictSet("Annots", Object(annotsRef));
         xref->setModifiedObject(&pageObj, pageRef);
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 46433285..58ca7d27 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -1295,7 +1295,7 @@ Object XRef::createDocInfoIfNeeded(Ref *ref)
     removeDocInfo();
 
     obj = Object(new Dict(this));
-    *ref = addIndirectObject(&obj);
+    *ref = addIndirectObject(obj);
     trailerDict.dictSet("Info", Object(*ref));
 
     return obj;
@@ -1404,7 +1404,7 @@ void XRef::setModifiedObject(const Object *o, Ref r)
     setModified();
 }
 
-Ref XRef::addIndirectObject(const Object *o)
+Ref XRef::addIndirectObject(const Object &o)
 {
     int entryIndexToUse = -1;
     for (int i = 1; entryIndexToUse == -1 && i < size; ++i) {
@@ -1426,7 +1426,7 @@ Ref XRef::addIndirectObject(const Object *o)
         // incremented when the object was deleted
     }
     e->type = xrefEntryUncompressed;
-    e->obj = o->copy();
+    e->obj = o.copy();
     e->setFlag(XRefEntry::Updated, true);
     setModified();
 
@@ -1461,8 +1461,7 @@ Ref XRef::addStreamObject(Dict *dict, char *buffer, const Goffset bufferSize)
     dict->add("Length", Object((int)bufferSize));
     AutoFreeMemStream *stream = new AutoFreeMemStream(buffer, 0, bufferSize, Object(dict));
     stream->setFilterRemovalForbidden(true);
-    Object streamObj((Stream *)stream);
-    return addIndirectObject(&streamObj);
+    return addIndirectObject(Object((Stream *)stream));
 }
 
 Ref XRef::addStreamObject(Dict *dict, uint8_t *buffer, const Goffset bufferSize)
diff --git a/poppler/XRef.h b/poppler/XRef.h
index a40c7312..05fce5b9 100644
--- a/poppler/XRef.h
+++ b/poppler/XRef.h
@@ -205,7 +205,7 @@ public:
 
     // Write access
     void setModifiedObject(const Object *o, Ref r);
-    Ref addIndirectObject(const Object *o);
+    Ref addIndirectObject(const Object &o);
     void removeIndirectObject(Ref r);
     void add(int num, int gen, Goffset offs, bool used);
     void add(Ref ref, Goffset offs, bool used);


More information about the poppler mailing list