Commit cbae2f916b8a7b4398d12632ecbc251456a75dae
1 parent
5d6ee83e
Remove use of non-standard `char_traits<unsigned char>` from Pl_Buffer
`basic_string<unsigned char>` implies use of `char_traits<unsigned char>`. This char_traits specialization is not standard C++, and will be removed from LibC++ as of LLVM 18. To ensure continued LibC++ compatibility it needs to be removed. There are two possible replacements here: `std::string` (e.g. `std::basic_string<char>`), or `std::vector<unsigned char>`. I have opted for vector since this code is dealing with a binary buffer; though probably either way is fine (why does C++ even have strings anyway??). https://github.com/qpdf/qpdf/issues/1024
Showing
2 changed files
with
5 additions
and
4 deletions
include/qpdf/Pl_Buffer.hh
| @@ -33,6 +33,7 @@ | @@ -33,6 +33,7 @@ | ||
| 33 | #include <qpdf/PointerHolder.hh> // unused -- remove in qpdf 12 (see #785) | 33 | #include <qpdf/PointerHolder.hh> // unused -- remove in qpdf 12 (see #785) |
| 34 | 34 | ||
| 35 | #include <memory> | 35 | #include <memory> |
| 36 | +#include <vector> | ||
| 36 | 37 | ||
| 37 | class QPDF_DLL_CLASS Pl_Buffer: public Pipeline | 38 | class QPDF_DLL_CLASS Pl_Buffer: public Pipeline |
| 38 | { | 39 | { |
| @@ -77,7 +78,7 @@ class QPDF_DLL_CLASS Pl_Buffer: public Pipeline | @@ -77,7 +78,7 @@ class QPDF_DLL_CLASS Pl_Buffer: public Pipeline | ||
| 77 | Members(Members const&) = delete; | 78 | Members(Members const&) = delete; |
| 78 | 79 | ||
| 79 | bool ready{true}; | 80 | bool ready{true}; |
| 80 | - std::basic_string<unsigned char> data; | 81 | + std::vector<unsigned char> data; |
| 81 | }; | 82 | }; |
| 82 | 83 | ||
| 83 | std::shared_ptr<Members> m; | 84 | std::shared_ptr<Members> m; |
libqpdf/Pl_Buffer.cc
| @@ -19,7 +19,7 @@ Pl_Buffer::~Pl_Buffer() // NOLINT (modernize-use-equals-default) | @@ -19,7 +19,7 @@ Pl_Buffer::~Pl_Buffer() // NOLINT (modernize-use-equals-default) | ||
| 19 | void | 19 | void |
| 20 | Pl_Buffer::write(unsigned char const* buf, size_t len) | 20 | Pl_Buffer::write(unsigned char const* buf, size_t len) |
| 21 | { | 21 | { |
| 22 | - m->data.append(buf, len); | 22 | + m->data.insert(m->data.end(), buf, buf + len); |
| 23 | m->ready = false; | 23 | m->ready = false; |
| 24 | 24 | ||
| 25 | if (getNext(true)) { | 25 | if (getNext(true)) { |
| @@ -43,7 +43,7 @@ Pl_Buffer::getBuffer() | @@ -43,7 +43,7 @@ Pl_Buffer::getBuffer() | ||
| 43 | throw std::logic_error("Pl_Buffer::getBuffer() called when not ready"); | 43 | throw std::logic_error("Pl_Buffer::getBuffer() called when not ready"); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | - auto size = m->data.length(); | 46 | + auto size = m->data.size(); |
| 47 | auto* b = new Buffer(size); | 47 | auto* b = new Buffer(size); |
| 48 | if (size > 0) { | 48 | if (size > 0) { |
| 49 | unsigned char* p = b->getBuffer(); | 49 | unsigned char* p = b->getBuffer(); |
| @@ -65,7 +65,7 @@ Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len) | @@ -65,7 +65,7 @@ Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len) | ||
| 65 | if (!m->ready) { | 65 | if (!m->ready) { |
| 66 | throw std::logic_error("Pl_Buffer::getMallocBuffer() called when not ready"); | 66 | throw std::logic_error("Pl_Buffer::getMallocBuffer() called when not ready"); |
| 67 | } | 67 | } |
| 68 | - auto size = m->data.length(); | 68 | + auto size = m->data.size(); |
| 69 | *len = size; | 69 | *len = size; |
| 70 | if (size > 0) { | 70 | if (size > 0) { |
| 71 | *buf = reinterpret_cast<unsigned char*>(malloc(size)); | 71 | *buf = reinterpret_cast<unsigned char*>(malloc(size)); |