diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-09-07 17:29:17 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-09-07 23:26:39 +0200 |
commit | 0132261ee06e9b94bdc011eb4dc3fcd3a403e5f3 (patch) | |
tree | 1d1d441bed9ca3621d6b0ee58aff664358311913 /libqpdf/QPDFObjectHandle.cc | |
parent | bac559559e7c218dd8a987cfebb395b2bc45eaee (diff) | |
download | qpdf-0132261ee06e9b94bdc011eb4dc3fcd3a403e5f3.tar.zst |
Revert getOwningQPDF, and add getQPDF that returns a reference
Diffstat (limited to 'libqpdf/QPDFObjectHandle.cc')
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 885abf3c..3d011c1d 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1668,11 +1668,10 @@ QPDFObjectHandle::coalesceContentStreams() // incorrect way. However, it can happen in a PDF file whose // page structure is direct, which is against spec but still // possible to hand construct, as in fuzz issue 27393. - QPDF* qpdf = getOwningQPDF( - false, + QPDF& qpdf = getQPDF( "coalesceContentStreams called on object with no associated PDF file"); - QPDFObjectHandle new_contents = newStream(qpdf); + QPDFObjectHandle new_contents = newStream(&qpdf); this->replaceKey("/Contents", new_contents); auto provider = std::shared_ptr<StreamDataProvider>( @@ -2775,16 +2774,20 @@ QPDFObjectHandle::getObjGen() const // Indirect object accessors QPDF* -QPDFObjectHandle::getOwningQPDF( - bool allow_nullptr, std::string const& error_msg) const +QPDFObjectHandle::getOwningQPDF() const +{ + return isInitialized() ? this->obj->getQPDF() : nullptr; +} + +QPDF& +QPDFObjectHandle::getQPDF(std::string const& error_msg) const { - // Will be null for direct objects auto result = isInitialized() ? this->obj->getQPDF() : nullptr; - if (!allow_nullptr && (result == nullptr)) { + if (result == nullptr) { throw std::runtime_error( error_msg == "" ? "attempt to use a null qpdf object" : error_msg); } - return result; + return *result; } void |