Commit 2d11e4dd9b2ca5122cb7fc04b82405eb3c9d5fdd

Authored by m-holger
1 parent 4181ec92

Refactor null object handling across helpers to use the `Null` class for consist…

…ent and simplified temporary null management. Clean up unused test coverage markers.
libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -252,16 +252,15 @@ QPDFFormFieldObjectHelper @@ -252,16 +252,15 @@ QPDFFormFieldObjectHelper
252 QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h) 252 QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h)
253 { 253 {
254 QPDFObjectHandle oh = h.getObjectHandle(); 254 QPDFObjectHandle oh = h.getObjectHandle();
255 - QPDFFormFieldObjectHelper result(QPDFObjectHandle::newNull());  
256 if (!oh.isDictionaryOfType("", "/Widget")) { 255 if (!oh.isDictionaryOfType("", "/Widget")) {
257 - return result; 256 + return Null::temp();
258 } 257 }
259 analyze(); 258 analyze();
260 QPDFObjGen og(oh.getObjGen()); 259 QPDFObjGen og(oh.getObjGen());
261 if (m->annotation_to_field.contains(og)) { 260 if (m->annotation_to_field.contains(og)) {
262 - result = m->annotation_to_field[og]; 261 + return m->annotation_to_field[og];
263 } 262 }
264 - return result; 263 + return Null::temp();
265 } 264 }
266 265
267 void 266 void
libqpdf/QPDFAnnotationObjectHelper.cc
@@ -56,20 +56,16 @@ QPDFAnnotationObjectHelper::getAppearanceStream(std::string const& which, std::s @@ -56,20 +56,16 @@ QPDFAnnotationObjectHelper::getAppearanceStream(std::string const& which, std::s
56 // appearance stream when /AP is a dictionary, but files have been seen in the wild 56 // appearance stream when /AP is a dictionary, but files have been seen in the wild
57 // where Appearance State is `/N` and `/AP` is a stream. Therefore, if `which` points to 57 // where Appearance State is `/N` and `/AP` is a stream. Therefore, if `which` points to
58 // a stream, disregard state and just use the stream. See qpdf issue #949 for details. 58 // a stream, disregard state and just use the stream. See qpdf issue #949 for details.
59 - QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP stream");  
60 return ap_sub; 59 return ap_sub;
61 } 60 }
62 - if (ap_sub.isDictionary() && (!desired_state.empty())) {  
63 - QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP dictionary"); 61 + if (ap_sub.isDictionary() && !desired_state.empty()) {
64 QPDFObjectHandle ap_sub_val = ap_sub.getKey(desired_state); 62 QPDFObjectHandle ap_sub_val = ap_sub.getKey(desired_state);
65 if (ap_sub_val.isStream()) { 63 if (ap_sub_val.isStream()) {
66 - QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP sub stream");  
67 return ap_sub_val; 64 return ap_sub_val;
68 } 65 }
69 } 66 }
70 } 67 }
71 - QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP null");  
72 - return QPDFObjectHandle::newNull(); 68 + return Null::temp();
73 } 69 }
74 70
75 std::string 71 std::string
libqpdf/QPDFEmbeddedFileDocumentHelper.cc
1 #include <qpdf/QPDFEmbeddedFileDocumentHelper.hh> 1 #include <qpdf/QPDFEmbeddedFileDocumentHelper.hh>
2 2
3 #include <qpdf/QPDFNameTreeObjectHelper.hh> 3 #include <qpdf/QPDFNameTreeObjectHelper.hh>
  4 +#include <qpdf/QPDFObjectHandle_private.hh>
4 #include <qpdf/QPDF_private.hh> 5 #include <qpdf/QPDF_private.hh>
5 6
6 // File attachments are stored in the /EmbeddedFiles (name tree) key of the /Names dictionary from 7 // File attachments are stored in the /EmbeddedFiles (name tree) key of the /Names dictionary from
@@ -143,11 +144,10 @@ QPDFEmbeddedFileDocumentHelper::removeEmbeddedFile(std::string const&amp; name) @@ -143,11 +144,10 @@ QPDFEmbeddedFileDocumentHelper::removeEmbeddedFile(std::string const&amp; name)
143 if (iter == m->embedded_files->end()) { 144 if (iter == m->embedded_files->end()) {
144 return false; 145 return false;
145 } 146 }
146 - auto oh = iter->second;  
147 - iter.remove();  
148 - if (oh.isIndirect()) {  
149 - qpdf.replaceObject(oh.getObjGen(), QPDFObjectHandle::newNull()); 147 + if (iter->second.indirect()) {
  148 + qpdf.replaceObject(iter->second, Null());
150 } 149 }
  150 + iter.remove();
151 151
152 return true; 152 return true;
153 } 153 }
libqpdf/QPDFFileSpecObjectHelper.cc
@@ -76,7 +76,7 @@ QPDFFileSpecObjectHelper::getEmbeddedFileStream(std::string const&amp; key) @@ -76,7 +76,7 @@ QPDFFileSpecObjectHelper::getEmbeddedFileStream(std::string const&amp; key)
76 } 76 }
77 } 77 }
78 } 78 }
79 - return QPDFObjectHandle::newNull(); 79 + return Null::temp();
80 } 80 }
81 81
82 QPDFObjectHandle 82 QPDFObjectHandle
qpdf/qpdf.testcov
@@ -181,10 +181,6 @@ QPDFFormFieldObjectHelper TU absent 0 @@ -181,10 +181,6 @@ QPDFFormFieldObjectHelper TU absent 0
181 QPDFFormFieldObjectHelper TM absent 0 181 QPDFFormFieldObjectHelper TM absent 0
182 QPDFFormFieldObjectHelper Q present 1 182 QPDFFormFieldObjectHelper Q present 1
183 QPDFFormFieldObjectHelper DA present 1 183 QPDFFormFieldObjectHelper DA present 1
184 -QPDFAnnotationObjectHelper AP stream 0  
185 -QPDFAnnotationObjectHelper AP dictionary 0  
186 -QPDFAnnotationObjectHelper AP sub stream 0  
187 -QPDFAnnotationObjectHelper AP null 0  
188 QPDFAcroFormDocumentHelper field found 1 184 QPDFAcroFormDocumentHelper field found 1
189 QPDFAcroFormDocumentHelper annotation found 1 185 QPDFAcroFormDocumentHelper annotation found 1
190 QPDFJob automatically set keep files open 1 186 QPDFJob automatically set keep files open 1