From d7b85252356da91293d9c11428a5a1c797c5dd0d Mon Sep 17 00:00:00 2001 From: m-holger Date: Mon, 14 Nov 2022 18:03:03 +0000 Subject: Refactor QPDFObjectHandle::unsafeShallowCopy --- include/qpdf/QPDFObjectHandle.hh | 1 - libqpdf/QPDFObjectHandle.cc | 17 ++++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index de9f51e9..24a3bead 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -1634,7 +1634,6 @@ class QPDFObjectHandle bool first_level_only, bool stop_at_streams); void shallowCopyInternal1(QPDFObjectHandle& oh, bool first_level_only); - void shallowCopyInternal2(QPDFObjectHandle& oh); void copyObject( std::set& visited, bool cross_indirect, diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 242e0fb2..9153e33f 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -2298,20 +2298,11 @@ QPDFObjectHandle::copyObject1( QPDFObjectHandle QPDFObjectHandle::unsafeShallowCopy() { - QPDFObjectHandle result; - shallowCopyInternal2(result); - return result; -} - -void -QPDFObjectHandle::shallowCopyInternal2(QPDFObjectHandle& new_obj) -{ - assertInitialized(); - - if (isStream()) { - throw std::runtime_error("attempt to make a shallow copy of a stream"); + if (!dereference()) { + throw std::logic_error("operation attempted on uninitialized " + "QPDFObjectHandle"); } - new_obj = QPDFObjectHandle(obj->copy(true)); + return QPDFObjectHandle(obj->copy(true)); } void -- cgit v1.2.3-54-g00ecf