From fe92a61de954e6eca0f96f1ee25a33262987b953 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 31 Aug 2025 13:12:54 +0100 Subject: [PATCH] Refactor: replace `isNull` calls with `null` in `QPDF` and remove redundant `QTC::TC` calls. --- libqpdf/QPDF_Dictionary.cc | 2 +- libqpdf/QPDF_Stream.cc | 2 +- libqpdf/QPDF_encryption.cc | 2 +- libqpdf/QPDF_linearization.cc | 8 ++++---- libqpdf/QPDF_objects.cc | 8 ++------ qpdf/qpdf.testcov | 4 ---- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index f02a7bb..f606b2b 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -40,7 +40,7 @@ BaseDictionary::getKeys() { std::set result; for (auto& iter: dict()->items) { - if (!iter.second.isNull()) { + if (!iter.second.null()) { result.insert(iter.first); } } diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 992cc84..73a9b38 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -376,7 +376,7 @@ Stream::filterable( auto filter_obj = s->stream_dict.getKey("/Filter"); - if (filter_obj.isNull()) { + if (filter_obj.null()) { // No filters return true; } diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index e5dca43..8be325a 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -681,7 +681,7 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) (encryption_dict.getKey("/Filter").getName() == "/Standard"))) { throw unsupported("unsupported encryption filter"); } - if (!encryption_dict.getKey("/SubFilter").isNull()) { + if (!encryption_dict.getKey("/SubFilter").null()) { qpdf.warn(unsupported("file uses encryption SubFilters, which qpdf does not support")); } diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 8ac8e51..bcce0e6 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -167,7 +167,7 @@ QPDF::readLinearizationData() QPDFObjectHandle P = m->lindict.getKey("/P"); if (!(H.isArray() && O.isInteger() && E.isInteger() && N.isInteger() && T.isInteger() && - (P.isInteger() || P.isNull()))) { + (P.isInteger() || P.null()))) { throw damagedPDF( "linearization dictionary", "some keys in linearization dictionary are of the wrong type"); @@ -577,7 +577,7 @@ QPDF::getUncompressedObject(QPDFObjectHandle& oh, QPDFWriter::ObjTable const& ob { if (obj.contains(oh)) { if (auto id = obj[oh].object_stream; id > 0) { - return oh.isNull() ? oh : getObject(id, 0); + return oh.null() ? oh : getObject(id, 0); } } return oh; @@ -1284,7 +1284,7 @@ QPDF::calculateLinearizationData(T const& object_stream_data) thumb = getUncompressedObject(thumb, object_stream_data); QPDFObjGen thumb_og(thumb.getObjGen()); // Output the thumbnail itself - if (lc_thumbnail_private.erase(thumb_og) && !thumb.isNull()) { + if (lc_thumbnail_private.erase(thumb_og) && !thumb.null()) { m->part9.emplace_back(thumb); } else { // No internal error this time...there's nothing to stop this object from having @@ -1394,7 +1394,7 @@ QPDF::pushOutlinesToPart( { QPDFObjectHandle root = getRoot(); QPDFObjectHandle outlines = root.getKey("/Outlines"); - if (outlines.isNull()) { + if (outlines.null()) { return; } outlines = getUncompressedObject(outlines, object_stream_data); diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index aa65e0d..354af00 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -910,8 +910,7 @@ QPDF::processXRefIndex( } QTC::TC("qpdf", "QPDF xref /Index is array", index_vec.size() == 2 ? 0 : 1); return {num_entries, indx}; - } else if (Index_obj.isNull()) { - QTC::TC("qpdf", "QPDF xref /Index is null"); + } else if (Index_obj.null()) { return {size, {{0, size}}}; } else { throw damaged("Cross-reference stream does not have a proper /Index key"); @@ -1256,11 +1255,9 @@ QPDF::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset) auto length_obj = object.getKey("/Length"); if (!length_obj.isInteger()) { - if (length_obj.isNull()) { - QTC::TC("qpdf", "QPDF stream without length"); + if (length_obj.null()) { throw damagedPDF(offset, "stream dictionary lacks /Length key"); } - QTC::TC("qpdf", "QPDF stream length not integer"); throw damagedPDF(offset, "/Length key in stream dictionary is not an integer"); } @@ -1269,7 +1266,6 @@ QPDF::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset) m->file->seek(stream_offset, SEEK_SET); m->file->seek(toO(length), SEEK_CUR); if (!readToken(*m->file).isWord("endstream")) { - QTC::TC("qpdf", "QPDF missing endstream"); throw damagedPDF("expected endstream"); } } catch (QPDFExc& e) { diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index e04c73e..942406d 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -64,9 +64,6 @@ QPDFParser bad brace 0 QPDFParser bad brace in parseRemainder 0 QPDFParser bad array close 0 QPDFParser bad array close in parseRemainder 0 -QPDF stream without length 0 -QPDF stream length not integer 0 -QPDF missing endstream 0 QPDFParser bad dictionary close 0 QPDFParser bad dictionary close in parseRemainder 0 QPDF can't find xref 0 @@ -87,7 +84,6 @@ QPDF found xref stream 0 QPDF ignoring XRefStm in trailer 0 QPDF xref deleted object 0 SF_FlateLzwDecode PNG filter 0 -QPDF xref /Index is null 0 QPDF xref /Index is array 1 QPDFWriter copy Extends 0 QPDFWriter encrypt object stream 0 -- libgit2 0.21.4