diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 169a930d..5457c68c 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -2176,7 +2176,8 @@ QPDFObjectHandle::setObjectDescription( // This is called during parsing on newly created direct objects, // so we can't call dereference() here. if (isInitialized() && obj.get()) { - obj->setDescription(owning_qpdf, object_description); + auto descr = std::make_shared(object_description); + obj->setDescription(owning_qpdf, descr); } } diff --git a/libqpdf/QPDFParser.cc b/libqpdf/QPDFParser.cc index 8bc9e10a..70c328e1 100644 --- a/libqpdf/QPDFParser.cc +++ b/libqpdf/QPDFParser.cc @@ -419,11 +419,10 @@ QPDFParser::setDescription( qpdf_offset_t parsed_offset) const { if (auto& obj = oh.obj) { - obj->setDescription( - context, - (input->getName() + ", " + object_description + " at offset " + - std::to_string(descr_offset)), - parsed_offset); + auto descr = std::make_shared( + input->getName() + ", " + object_description + " at offset " + + std::to_string(descr_offset)); + obj->setDescription(context, descr, parsed_offset); } } diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 7ff7a1b8..b5aac026 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -123,10 +123,9 @@ QPDF_Stream::QPDF_Stream( throw std::logic_error("stream object instantiated with non-dictionary " "object for dictionary"); } - setDescription( - qpdf, - qpdf->getFilename() + ", stream object " + og.unparse(' '), - offset); + auto descr = std::make_shared( + qpdf->getFilename() + ", stream object " + og.unparse(' ')); + setDescription(qpdf, descr, offset); } std::shared_ptr @@ -284,7 +283,7 @@ QPDF_Stream::getStreamJSON( void QPDF_Stream::setDescription( - QPDF* qpdf, std::string const& description, qpdf_offset_t offset) + QPDF* qpdf, std::shared_ptr& description, qpdf_offset_t offset) { this->QPDFValue::setDescription(qpdf, description, offset); setDictDescription(); diff --git a/libqpdf/qpdf/QPDFObject_private.hh b/libqpdf/qpdf/QPDFObject_private.hh index 3356e3e5..416483c2 100644 --- a/libqpdf/qpdf/QPDFObject_private.hh +++ b/libqpdf/qpdf/QPDFObject_private.hh @@ -70,7 +70,9 @@ class QPDFObject } void setDescription( - QPDF* qpdf, std::string const& description, qpdf_offset_t offset = -1) + QPDF* qpdf, + std::shared_ptr& description, + qpdf_offset_t offset = -1) { return value->setDescription(qpdf, description, offset); } diff --git a/libqpdf/qpdf/QPDFParser.hh b/libqpdf/qpdf/QPDFParser.hh index 45d36695..28768df2 100644 --- a/libqpdf/qpdf/QPDFParser.hh +++ b/libqpdf/qpdf/QPDFParser.hh @@ -40,7 +40,6 @@ class QPDFParser void warn(qpdf_offset_t offset, std::string const& msg) const; void warn(std::string const& msg) const; static void warn(QPDF*, QPDFExc const&); - void setDescription( QPDFObjectHandle oh, qpdf_offset_t descr_offset, diff --git a/libqpdf/qpdf/QPDFValue.hh b/libqpdf/qpdf/QPDFValue.hh index e4c038b6..d6fab5ca 100644 --- a/libqpdf/qpdf/QPDFValue.hh +++ b/libqpdf/qpdf/QPDFValue.hh @@ -25,7 +25,9 @@ class QPDFValue virtual JSON getJSON(int json_version) = 0; virtual void setDescription( - QPDF* qpdf_p, std::string const& description, qpdf_offset_t offset) + QPDF* qpdf_p, + std::shared_ptr& description, + qpdf_offset_t offset) { qpdf = qpdf_p; object_description = description; @@ -34,8 +36,9 @@ class QPDFValue void setDefaultDescription(QPDF* a_qpdf, QPDFObjGen const& a_og) { - if (object_description.empty()) { - object_description = "object " + a_og.unparse(' '); + if (!object_description) { + object_description = + std::make_shared("object " + a_og.unparse(' ')); } qpdf = a_qpdf; og = a_og; @@ -44,13 +47,14 @@ class QPDFValue getDescription(QPDF*& qpdf_p, std::string& description) { qpdf_p = qpdf; - description = object_description; + description = object_description ? *object_description : ""; return qpdf != nullptr; } bool hasDescription() { - return qpdf != nullptr && !object_description.empty(); + return qpdf != nullptr && object_description && + !object_description->empty(); } void setParsedOffset(qpdf_offset_t offset) @@ -109,7 +113,7 @@ class QPDFValue private: QPDFValue(QPDFValue const&) = delete; QPDFValue& operator=(QPDFValue const&) = delete; - std::string object_description; + std::shared_ptr object_description; const qpdf_object_type_e type_code{::ot_uninitialized}; char const* type_name{"uninitialized"}; diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index a436420a..c0694c60 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -26,8 +26,8 @@ class QPDF_Stream: public QPDFValue virtual std::shared_ptr copy(bool shallow = false); virtual std::string unparse(); virtual JSON getJSON(int json_version); - virtual void - setDescription(QPDF*, std::string const&, qpdf_offset_t offset); + virtual void setDescription( + QPDF*, std::shared_ptr& description, qpdf_offset_t offset); virtual void disconnect(); QPDFObjectHandle getDict() const; bool isDataModified() const;