aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Buffer.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-02 23:14:10 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-04 14:10:40 +0200
commit12f1eb15ca3fed6310402847559a7c99d3c77847 (patch)
tree8935675b623c6f3b4914b8b44f7fa5f2816a9241 /libqpdf/Pl_Buffer.cc
parentf20fa61eb4c323eb1642c69c236b3d9a1f8b2cdb (diff)
downloadqpdf-12f1eb15ca3fed6310402847559a7c99d3c77847.tar.zst
Programmatically apply new formatting to code
Run this: for i in **/*.cc **/*.c **/*.h **/*.hh; do clang-format < $i >| $i.new && mv $i.new $i done
Diffstat (limited to 'libqpdf/Pl_Buffer.cc')
-rw-r--r--libqpdf/Pl_Buffer.cc37
1 files changed, 13 insertions, 24 deletions
diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc
index b38edc98..dba91e0f 100644
--- a/libqpdf/Pl_Buffer.cc
+++ b/libqpdf/Pl_Buffer.cc
@@ -1,10 +1,10 @@
#include <qpdf/Pl_Buffer.hh>
-#include <stdexcept>
#include <algorithm>
#include <assert.h>
-#include <string.h>
+#include <stdexcept>
#include <stdlib.h>
+#include <string.h>
Pl_Buffer::Members::Members() :
ready(true),
@@ -29,28 +29,24 @@ Pl_Buffer::~Pl_Buffer()
void
Pl_Buffer::write(unsigned char* buf, size_t len)
{
- if (this->m->data.get() == 0)
- {
+ if (this->m->data.get() == 0) {
this->m->data = make_pointer_holder<Buffer>(len);
}
size_t cur_size = this->m->data->getSize();
size_t left = cur_size - this->m->total_size;
- if (left < len)
- {
+ if (left < len) {
size_t new_size = std::max(this->m->total_size + len, 2 * cur_size);
auto b = make_pointer_holder<Buffer>(new_size);
memcpy(b->getBuffer(), this->m->data->getBuffer(), this->m->total_size);
this->m->data = b;
}
- if (len)
- {
+ if (len) {
memcpy(this->m->data->getBuffer() + this->m->total_size, buf, len);
this->m->total_size += len;
}
this->m->ready = false;
- if (getNext(true))
- {
+ if (getNext(true)) {
getNext()->write(buf, len);
}
}
@@ -59,8 +55,7 @@ void
Pl_Buffer::finish()
{
this->m->ready = true;
- if (getNext(true))
- {
+ if (getNext(true)) {
getNext()->finish();
}
}
@@ -68,14 +63,12 @@ Pl_Buffer::finish()
Buffer*
Pl_Buffer::getBuffer()
{
- if (! this->m->ready)
- {
+ if (!this->m->ready) {
throw std::logic_error("Pl_Buffer::getBuffer() called when not ready");
}
Buffer* b = new Buffer(this->m->total_size);
- if (this->m->total_size > 0)
- {
+ if (this->m->total_size > 0) {
unsigned char* p = b->getBuffer();
memcpy(p, this->m->data->getBuffer(), this->m->total_size);
}
@@ -90,22 +83,18 @@ Pl_Buffer::getBufferSharedPointer()
}
void
-Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len)
+Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len)
{
- if (! this->m->ready)
- {
+ if (!this->m->ready) {
throw std::logic_error(
"Pl_Buffer::getMallocBuffer() called when not ready");
}
*len = this->m->total_size;
- if (this->m->total_size > 0)
- {
+ if (this->m->total_size > 0) {
*buf = reinterpret_cast<unsigned char*>(malloc(this->m->total_size));
memcpy(*buf, this->m->data->getBuffer(), this->m->total_size);
- }
- else
- {
+ } else {
*buf = nullptr;
}
this->m = PointerHolder<Members>(new Members());