From 2d11e4dd9b2ca5122cb7fc04b82405eb3c9d5fdd Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 8 Nov 2025 00:26:36 +0000 Subject: [PATCH] Refactor null object handling across helpers to use the `Null` class for consistent and simplified temporary null management. Clean up unused test coverage markers. --- libqpdf/QPDFAcroFormDocumentHelper.cc | 7 +++---- libqpdf/QPDFAnnotationObjectHelper.cc | 8 ++------ libqpdf/QPDFEmbeddedFileDocumentHelper.cc | 8 ++++---- libqpdf/QPDFFileSpecObjectHelper.cc | 2 +- qpdf/qpdf.testcov | 4 ---- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 2f0d629..4fb3ec3 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -252,16 +252,15 @@ QPDFFormFieldObjectHelper QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h) { QPDFObjectHandle oh = h.getObjectHandle(); - QPDFFormFieldObjectHelper result(QPDFObjectHandle::newNull()); if (!oh.isDictionaryOfType("", "/Widget")) { - return result; + return Null::temp(); } analyze(); QPDFObjGen og(oh.getObjGen()); if (m->annotation_to_field.contains(og)) { - result = m->annotation_to_field[og]; + return m->annotation_to_field[og]; } - return result; + return Null::temp(); } void diff --git a/libqpdf/QPDFAnnotationObjectHelper.cc b/libqpdf/QPDFAnnotationObjectHelper.cc index ce2b12d..63e3628 100644 --- a/libqpdf/QPDFAnnotationObjectHelper.cc +++ b/libqpdf/QPDFAnnotationObjectHelper.cc @@ -56,20 +56,16 @@ QPDFAnnotationObjectHelper::getAppearanceStream(std::string const& which, std::s // appearance stream when /AP is a dictionary, but files have been seen in the wild // where Appearance State is `/N` and `/AP` is a stream. Therefore, if `which` points to // a stream, disregard state and just use the stream. See qpdf issue #949 for details. - QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP stream"); return ap_sub; } - if (ap_sub.isDictionary() && (!desired_state.empty())) { - QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP dictionary"); + if (ap_sub.isDictionary() && !desired_state.empty()) { QPDFObjectHandle ap_sub_val = ap_sub.getKey(desired_state); if (ap_sub_val.isStream()) { - QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP sub stream"); return ap_sub_val; } } } - QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP null"); - return QPDFObjectHandle::newNull(); + return Null::temp(); } std::string diff --git a/libqpdf/QPDFEmbeddedFileDocumentHelper.cc b/libqpdf/QPDFEmbeddedFileDocumentHelper.cc index bdc86ad..d44c1ff 100644 --- a/libqpdf/QPDFEmbeddedFileDocumentHelper.cc +++ b/libqpdf/QPDFEmbeddedFileDocumentHelper.cc @@ -1,6 +1,7 @@ #include #include +#include #include // File attachments are stored in the /EmbeddedFiles (name tree) key of the /Names dictionary from @@ -143,11 +144,10 @@ QPDFEmbeddedFileDocumentHelper::removeEmbeddedFile(std::string const& name) if (iter == m->embedded_files->end()) { return false; } - auto oh = iter->second; - iter.remove(); - if (oh.isIndirect()) { - qpdf.replaceObject(oh.getObjGen(), QPDFObjectHandle::newNull()); + if (iter->second.indirect()) { + qpdf.replaceObject(iter->second, Null()); } + iter.remove(); return true; } diff --git a/libqpdf/QPDFFileSpecObjectHelper.cc b/libqpdf/QPDFFileSpecObjectHelper.cc index d92aac4..570b056 100644 --- a/libqpdf/QPDFFileSpecObjectHelper.cc +++ b/libqpdf/QPDFFileSpecObjectHelper.cc @@ -76,7 +76,7 @@ QPDFFileSpecObjectHelper::getEmbeddedFileStream(std::string const& key) } } } - return QPDFObjectHandle::newNull(); + return Null::temp(); } QPDFObjectHandle diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 2c10208..8c9646e 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -181,10 +181,6 @@ QPDFFormFieldObjectHelper TU absent 0 QPDFFormFieldObjectHelper TM absent 0 QPDFFormFieldObjectHelper Q present 1 QPDFFormFieldObjectHelper DA present 1 -QPDFAnnotationObjectHelper AP stream 0 -QPDFAnnotationObjectHelper AP dictionary 0 -QPDFAnnotationObjectHelper AP sub stream 0 -QPDFAnnotationObjectHelper AP null 0 QPDFAcroFormDocumentHelper field found 1 QPDFAcroFormDocumentHelper annotation found 1 QPDFJob automatically set keep files open 1 -- libgit2 0.21.4