summaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-05-25 15:10:47 +0200
committerm-holger <m-holger@kubitscheck.org>2023-06-17 18:18:31 +0200
commit0f2ef5e85bce0d64683e8071151711f21fa3e052 (patch)
tree5aee7e0f1c37f1acca3f4d4f7a390d5e409b2b81 /libqpdf
parentacd0acf16931ce92bc908e4960c5a1e43d53b550 (diff)
downloadqpdf-0f2ef5e85bce0d64683e8071151711f21fa3e052.tar.zst
Add new Buffer method copy and deprecate copy constructor / assignment operator
Also fix accidental Buffer copy in Pl_LZWDecoder::addToTable.
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/Buffer.cc25
-rw-r--r--libqpdf/Pl_LZWDecoder.cc2
2 files changed, 26 insertions, 1 deletions
diff --git a/libqpdf/Buffer.cc b/libqpdf/Buffer.cc
index ae04fbc8..3dddd5db 100644
--- a/libqpdf/Buffer.cc
+++ b/libqpdf/Buffer.cc
@@ -1,7 +1,20 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/Buffer.hh>
#include <cstring>
+bool test_mode = false;
+
+// During CI the Buffer copy constructor and copy assignment operator throw an assertion error to
+// detect their accidental use. Call setTestMode to surpress the assertion errors for testing of
+// copy construction and assignment.
+void
+Buffer::setTestMode() noexcept
+{
+ test_mode = true;
+}
+
Buffer::Members::Members(size_t size, unsigned char* buf, bool own_memory) :
own_memory(own_memory),
size(size),
@@ -38,12 +51,14 @@ Buffer::Buffer(unsigned char* buf, size_t size) :
Buffer::Buffer(Buffer const& rhs)
{
+ assert(test_mode);
copy(rhs);
}
Buffer&
Buffer::operator=(Buffer const& rhs)
{
+ assert(test_mode);
copy(rhs);
return *this;
}
@@ -88,3 +103,13 @@ Buffer::getBuffer()
{
return m->buf;
}
+
+Buffer
+Buffer::copy() const
+{
+ auto result = Buffer(m->size);
+ if (m->size) {
+ memcpy(result.m->buf, m->buf, m->size);
+ }
+ return result;
+}
diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc
index 4ffcaa3f..9abb69cd 100644
--- a/libqpdf/Pl_LZWDecoder.cc
+++ b/libqpdf/Pl_LZWDecoder.cc
@@ -129,7 +129,7 @@ Pl_LZWDecoder::addToTable(unsigned char next)
unsigned char* new_data = entry.getBuffer();
memcpy(new_data, last_data, last_size);
new_data[last_size] = next;
- this->table.push_back(entry);
+ this->table.push_back(std::move(entry));
}
void