aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2022-12-16 15:53:47 +0100
committerJay Berkenbilt <jberkenbilt@users.noreply.github.com>2022-12-31 16:23:59 +0100
commite684d8169bc866c413b269005c7645fd28146d10 (patch)
tree79d70c6f6c0d161b4d3810b6a0235d661ef3a926 /libqpdf
parent218f069a69ef74d0b0cc9c7ba0796e9360cef379 (diff)
downloadqpdf-e684d8169bc866c413b269005c7645fd28146d10.tar.zst
Make QPDFValue::object_description a shared pointer
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFObjectHandle.cc3
-rw-r--r--libqpdf/QPDFParser.cc9
-rw-r--r--libqpdf/QPDF_Stream.cc9
-rw-r--r--libqpdf/qpdf/QPDFObject_private.hh4
-rw-r--r--libqpdf/qpdf/QPDFParser.hh1
-rw-r--r--libqpdf/qpdf/QPDFValue.hh16
-rw-r--r--libqpdf/qpdf/QPDF_Stream.hh4
7 files changed, 25 insertions, 21 deletions
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<std::string>(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<std::string>(
+ 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<std::string>(
+ qpdf->getFilename() + ", stream object " + og.unparse(' '));
+ setDescription(qpdf, descr, offset);
}
std::shared_ptr<QPDFObject>
@@ -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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>("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<std::string> 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<QPDFObject> 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<std::string>& description, qpdf_offset_t offset);
virtual void disconnect();
QPDFObjectHandle getDict() const;
bool isDataModified() const;