aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-11-16 17:26:04 +0100
committerm-holger <m-holger@kubitscheck.org>2023-11-18 17:34:17 +0100
commit3237ef70fb77ce323394de1e2793abdb5ae85384 (patch)
tree2b8e132b26017507db151174944651741d3b71d1 /libqpdf
parentd11622b6fd8a2d050414c3e6110f3ad68f7502af (diff)
downloadqpdf-3237ef70fb77ce323394de1e2793abdb5ae85384.tar.zst
Add new method Pl_Buffer::getString
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/Pl_Buffer.cc11
-rw-r--r--libqpdf/QPDFAcroFormDocumentHelper.cc3
-rw-r--r--libqpdf/QPDFObjectHandle.cc3
-rw-r--r--libqpdf/QPDFWriter.cc5
-rw-r--r--libqpdf/QPDF_encryption.cc9
5 files changed, 17 insertions, 14 deletions
diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc
index 072b04d4..05d2ebdb 100644
--- a/libqpdf/Pl_Buffer.cc
+++ b/libqpdf/Pl_Buffer.cc
@@ -53,6 +53,17 @@ Pl_Buffer::getBuffer()
return b;
}
+std::string
+Pl_Buffer::getString()
+{
+ if (!m->ready) {
+ throw std::logic_error("Pl_Buffer::getString() called when not ready");
+ }
+ auto s = std::move(m->data);
+ m->data.clear();
+ return s;
+}
+
std::shared_ptr<Buffer>
Pl_Buffer::getBufferSharedPointer()
{
diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc
index 5a54bf75..f2daa0c7 100644
--- a/libqpdf/QPDFAcroFormDocumentHelper.cc
+++ b/libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -584,8 +584,7 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances(
ResourceReplacer rr(dr_map, rf.getNamesByResourceType());
Pl_Buffer buf_pl("filtered DA");
da_stream.filterAsContents(&rr, &buf_pl);
- auto buf = buf_pl.getBufferSharedPointer();
- std::string new_da(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
+ std::string new_da = buf_pl.getString();
obj.replaceKey("/DA", QPDFObjectHandle::newString(new_da));
}
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index d5ac137a..d543f98e 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -1708,8 +1708,7 @@ QPDFObjectHandle::pipeContentStreams(
need_newline = (lc.getLastChar() != static_cast<unsigned char>('\n'));
QTC::TC("qpdf", "QPDFObjectHandle need_newline", need_newline ? 0 : 1);
}
- std::unique_ptr<Buffer> b(buf.getBuffer());
- p->write(b->getBuffer(), b->getSize());
+ p->writeString(buf.getString());
p->finish();
}
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index db3b42e0..664ea5ff 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -1579,10 +1579,7 @@ QPDFWriter::unparseObject(
m->cur_data_key.length());
pl.writeString(val);
pl.finish();
- auto buf = bufpl.getBufferSharedPointer();
- val = QPDF_String(
- std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()))
- .unparse(true);
+ val = QPDF_String(bufpl.getString()).unparse(true);
} else {
auto tmp_ph = QUtil::make_unique_cstr(val);
char* tmp = tmp_ph.get();
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
index b5cc44ee..d405b4dd 100644
--- a/libqpdf/QPDF_encryption.cc
+++ b/libqpdf/QPDF_encryption.cc
@@ -229,13 +229,11 @@ process_with_aes(
aes.writeString(data);
}
aes.finish();
- auto bufp = buffer.getBufferSharedPointer();
if (outlength == 0) {
- outlength = bufp->getSize();
+ return buffer.getString();
} else {
- outlength = std::min(outlength, bufp->getSize());
+ return buffer.getString().substr(0, outlength);
}
- return {reinterpret_cast<char*>(bufp->getBuffer()), outlength};
}
static std::string
@@ -1021,8 +1019,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og)
key.length());
pl.writeString(str);
pl.finish();
- auto buf = bufpl.getBufferSharedPointer();
- str = std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
+ str = bufpl.getString();
} else {
QTC::TC("qpdf", "QPDF_encryption rc4 decode string");
size_t vlen = str.length();