Skip to content

Commit

Permalink
Merge pull request qpdf#734 from m-holger/nullptr
Browse files Browse the repository at this point in the history
Code tidy : replace 0 with nullptr or true
  • Loading branch information
jberkenbilt authored Jul 31, 2022
2 parents c9cc8cf + 073808a commit 4feb10f
Show file tree
Hide file tree
Showing 49 changed files with 193 additions and 187 deletions.
12 changes: 6 additions & 6 deletions examples/pdf-attach-file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// the use of the qpdf literal syntax introduced in qpdf 10.6.
//

static char const* whoami = 0;
static char const* whoami = nullptr;

static void
usage(std::string const& msg)
Expand Down Expand Up @@ -167,11 +167,11 @@ main(int argc, char* argv[])
{
whoami = QUtil::getWhoami(argv[0]);

char const* infilename = 0;
char const* password = 0;
char const* attachment = 0;
char const* outfilename = 0;
char const* mimetype = 0;
char const* infilename = nullptr;
char const* password = nullptr;
char const* attachment = nullptr;
char const* outfilename = nullptr;
char const* mimetype = nullptr;

auto check_arg = [](char const* arg, std::string const& msg) {
if (arg == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-bookmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// Ignore calls to QTC::TC - they are for qpdf CI testing only.

static char const* whoami = 0;
static char const* whoami = nullptr;
static enum { st_none, st_numbers, st_lines } style = st_none;
static bool show_open = false;
static bool show_targets = false;
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-count-strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <qpdf/QPDFPageObjectHelper.hh>
#include <qpdf/QUtil.hh>

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <stdlib.h>
#include <string.h>

static char const* whoami = 0;
static char const* whoami = nullptr;

// This is a simple StreamDataProvider that writes image data for an
// orange square of the given width and height.
Expand Down
6 changes: 3 additions & 3 deletions examples/pdf-custom-filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// of running this example on test files that are specifically crafted
// for it.

static char const* whoami = 0;
static char const* whoami = nullptr;

class Pl_XOR: public Pipeline
{
Expand Down Expand Up @@ -447,8 +447,8 @@ main(int argc, char* argv[])
{
whoami = QUtil::getWhoami(argv[0]);

char const* infilename = 0;
char const* outfilename = 0;
char const* infilename = nullptr;
char const* outfilename = nullptr;
bool decode_specialized = false;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--decode-specialized") == 0) {
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-double-page-size.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdlib.h>
#include <string.h>

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-filter-tokens.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <qpdf/QPDFWriter.hh>
#include <qpdf/QUtil.hh>

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down
5 changes: 3 additions & 2 deletions examples/pdf-invert-images.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <stdlib.h>
#include <string.h>

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down Expand Up @@ -142,7 +142,8 @@ main(int argc, char* argv[])
// pipeStreamData with a null pipeline to determine
// whether the image is filterable. Directly inspect
// keys to determine the image type.
if (image.pipeStreamData(0, qpdf_ef_compress, qpdf_dl_all) &&
if (image.pipeStreamData(
nullptr, qpdf_ef_compress, qpdf_dl_all) &&
color_space.isNameAndEquals("/DeviceGray") &&
bits_per_component.isInteger() &&
(bits_per_component.getIntValue() == 8)) {
Expand Down
6 changes: 3 additions & 3 deletions examples/pdf-mod-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <string.h>

static char const* version = "1.1";
static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down Expand Up @@ -77,8 +77,8 @@ main(int argc, char* argv[])
exit(0);
}

char* fl_in = 0;
char* fl_out = 0;
char* fl_in = nullptr;
char* fl_out = nullptr;
std::string cur_key;

for (int i = 1; i < argc; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-name-number-tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <cstring>
#include <iostream>

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-npages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <qpdf/QPDF.hh>
#include <qpdf/QUtil.hh>

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-overlay-page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// --overlay and --underlay options provide a more general version of
// this capability.

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-parse-content.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <qpdf/QPDFPageObjectHelper.hh>
#include <qpdf/QUtil.hh>

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf-set-form-values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdlib.h>
#include <string.h>

static char const* whoami = 0;
static char const* whoami = nullptr;

void
usage()
Expand Down
2 changes: 1 addition & 1 deletion examples/qpdf-job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// This program is a simple demonstration of different ways to use the
// QPDFJob API.

static char const* whoami = 0;
static char const* whoami = nullptr;

static void
usage()
Expand Down
11 changes: 6 additions & 5 deletions libqpdf/Buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
Buffer::Members::Members(size_t size, unsigned char* buf, bool own_memory) :
own_memory(own_memory),
size(size),
buf(0)
buf(nullptr)
{
if (own_memory) {
this->buf = (size ? new unsigned char[size] : 0);
this->buf = (size ? new unsigned char[size] : nullptr);
} else {
this->buf = buf;
}
Expand All @@ -22,12 +22,12 @@ Buffer::Members::~Members()
}

Buffer::Buffer() :
m(new Members(0, 0, true))
m(new Members(0, nullptr, true))
{
}

Buffer::Buffer(size_t size) :
m(new Members(size, 0, true))
m(new Members(size, nullptr, true))
{
}

Expand All @@ -52,7 +52,8 @@ void
Buffer::copy(Buffer const& rhs)
{
if (this != &rhs) {
this->m = std::shared_ptr<Members>(new Members(rhs.m->size, 0, true));
this->m =
std::shared_ptr<Members>(new Members(rhs.m->size, nullptr, true));
if (this->m->size) {
memcpy(this->m->buf, rhs.m->buf, this->m->size);
}
Expand Down
2 changes: 1 addition & 1 deletion libqpdf/BufferInputSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BufferInputSource::BufferInputSource(

BufferInputSource::BufferInputSource(
std::string const& description, std::string const& contents) :
m(new Members(true, description, 0))
m(new Members(true, description, nullptr))
{
this->m->buf = new Buffer(contents.length());
this->m->max_offset = QIntC::to_offset(this->m->buf->getSize());
Expand Down
4 changes: 2 additions & 2 deletions libqpdf/ClosedFileInputSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ClosedFileInputSource::~ClosedFileInputSource()
void
ClosedFileInputSource::before()
{
if (0 == this->m->fis.get()) {
if (nullptr == this->m->fis.get()) {
this->m->fis =
std::make_shared<FileInputSource>(this->m->filename.c_str());
this->m->fis->seek(this->m->offset, SEEK_SET);
Expand All @@ -39,7 +39,7 @@ ClosedFileInputSource::after()
if (this->m->stay_open) {
return;
}
this->m->fis = 0;
this->m->fis = nullptr;
}

qpdf_offset_t
Expand Down
2 changes: 1 addition & 1 deletion libqpdf/FileInputSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

FileInputSource::Members::Members(bool close_file) :
close_file(close_file),
file(0)
file(nullptr)
{
}

Expand Down
7 changes: 4 additions & 3 deletions libqpdf/InputSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ InputSource::findFirst(
" too small or too large of a character sequence");
}

char* p = 0;
char* p = nullptr;
qpdf_offset_t buf_offset = offset;
size_t bytes_read = 0;

Expand All @@ -86,7 +86,8 @@ InputSource::findFirst(
// If p points to buf[size], since strlen(start_chars) is
// always >= 1, this overflow test will be correct for that
// case regardless of start_chars.
if ((p == 0) || ((p + strlen(start_chars)) > (buf + bytes_read))) {
if ((p == nullptr) ||
((p + strlen(start_chars)) > (buf + bytes_read))) {
if (p) {
QTC::TC(
"libtests",
Expand Down Expand Up @@ -117,7 +118,7 @@ InputSource::findFirst(
memchr(
p,
start_chars[0],
bytes_read - QIntC::to_size(p - buf)))) != 0) {
bytes_read - QIntC::to_size(p - buf)))) != nullptr) {
if (p == buf) {
QTC::TC("libtests", "InputSource found match at buf[0]");
}
Expand Down
8 changes: 4 additions & 4 deletions libqpdf/JSON.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ JSON::JSON_blob::write(Pipeline* p, size_t) const
void
JSON::write(Pipeline* p, size_t depth) const
{
if (0 == this->m->value.get()) {
if (nullptr == this->m->value.get()) {
*p << "null";
} else {
this->m->value->write(p, depth);
Expand Down Expand Up @@ -270,7 +270,7 @@ JSON
JSON::addDictionaryMember(std::string const& key, JSON const& val)
{
JSON_dictionary* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get());
if (0 == obj) {
if (nullptr == obj) {
throw std::runtime_error(
"JSON::addDictionaryMember called on non-dictionary");
}
Expand All @@ -286,7 +286,7 @@ bool
JSON::checkDictionaryKeySeen(std::string const& key)
{
JSON_dictionary* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get());
if (0 == obj) {
if (nullptr == obj) {
throw std::logic_error(
"JSON::checkDictionaryKey called on non-dictionary");
}
Expand All @@ -307,7 +307,7 @@ JSON
JSON::addArrayElement(JSON const& val)
{
JSON_array* arr = dynamic_cast<JSON_array*>(this->m->value.get());
if (0 == arr) {
if (nullptr == arr) {
throw std::runtime_error("JSON::addArrayElement called on non-array");
}
if (val.m->value.get()) {
Expand Down
2 changes: 1 addition & 1 deletion libqpdf/Pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pipeline::Pipeline(char const* identifier, Pipeline* next) :
Pipeline*
Pipeline::getNext(bool allow_null)
{
if ((this->next == 0) && (!allow_null)) {
if ((this->next == nullptr) && (!allow_null)) {
throw std::logic_error(
this->identifier +
": Pipeline::getNext() called on pipeline with no next");
Expand Down
2 changes: 1 addition & 1 deletion libqpdf/Pl_Buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Pl_Buffer::~Pl_Buffer()
void
Pl_Buffer::write(unsigned char const* buf, size_t len)
{
if (this->m->data.get() == 0) {
if (this->m->data.get() == nullptr) {
this->m->data = std::make_shared<Buffer>(len);
}
size_t cur_size = this->m->data->getSize();
Expand Down
2 changes: 1 addition & 1 deletion libqpdf/Pl_Discard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Exercised in md5 test suite

Pl_Discard::Pl_Discard() :
Pipeline("discard", 0)
Pipeline("discard", nullptr)
{
}

Expand Down
16 changes: 8 additions & 8 deletions libqpdf/Pl_Flate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Pl_Flate::Members::Members(size_t out_bufsize, action_e action) :
out_bufsize(out_bufsize),
action(action),
initialized(false),
zdata(0)
zdata(nullptr)
{
this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize);
// Indirect through zdata to reach the z_stream so we don't have
Expand All @@ -29,10 +29,10 @@ Pl_Flate::Members::Members(size_t out_bufsize, action_e action) :
}

z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
zstream.zalloc = 0;
zstream.zfree = 0;
zstream.opaque = 0;
zstream.next_in = 0;
zstream.zalloc = nullptr;
zstream.zfree = nullptr;
zstream.opaque = nullptr;
zstream.next_in = nullptr;
zstream.avail_in = 0;
zstream.next_out = this->outbuf.get();
zstream.avail_out = QIntC::to_uint(out_bufsize);
Expand All @@ -50,7 +50,7 @@ Pl_Flate::Members::~Members()
}

delete static_cast<z_stream*>(this->zdata);
this->zdata = 0;
this->zdata = nullptr;
}

Pl_Flate::Pl_Flate(
Expand Down Expand Up @@ -86,7 +86,7 @@ Pl_Flate::warn(char const* msg, int code)
void
Pl_Flate::write(unsigned char const* data, size_t len)
{
if (this->m->outbuf.get() == 0) {
if (this->m->outbuf.get() == nullptr) {
throw std::logic_error(
this->identifier +
": Pl_Flate: write() called after finish() called");
Expand Down Expand Up @@ -227,7 +227,7 @@ Pl_Flate::finish()
checkError("End", err);
}

this->m->outbuf = 0;
this->m->outbuf = nullptr;
}
} catch (std::exception& e) {
try {
Expand Down
Loading

0 comments on commit 4feb10f

Please sign in to comment.