From 073808aa50f0c78e2d6fea4f56f0b814b314eb42 Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 26 Jul 2022 12:37:50 +0100 Subject: [PATCH] Code tidy : replace 0 with nullptr or true --- examples/pdf-attach-file.cc | 12 +++---- examples/pdf-bookmarks.cc | 2 +- examples/pdf-count-strings.cc | 2 +- examples/pdf-create.cc | 2 +- examples/pdf-custom-filter.cc | 6 ++-- examples/pdf-double-page-size.cc | 2 +- examples/pdf-filter-tokens.cc | 2 +- examples/pdf-invert-images.cc | 5 +-- examples/pdf-mod-info.cc | 6 ++-- examples/pdf-name-number-tree.cc | 2 +- examples/pdf-npages.cc | 2 +- examples/pdf-overlay-page.cc | 2 +- examples/pdf-parse-content.cc | 2 +- examples/pdf-set-form-values.cc | 2 +- examples/qpdf-job.cc | 2 +- libqpdf/Buffer.cc | 11 +++--- libqpdf/BufferInputSource.cc | 2 +- libqpdf/ClosedFileInputSource.cc | 4 +-- libqpdf/FileInputSource.cc | 2 +- libqpdf/InputSource.cc | 7 ++-- libqpdf/JSON.cc | 8 ++--- libqpdf/Pipeline.cc | 2 +- libqpdf/Pl_Buffer.cc | 2 +- libqpdf/Pl_Discard.cc | 2 +- libqpdf/Pl_Flate.cc | 16 ++++----- libqpdf/Pl_LZWDecoder.cc | 4 +-- libqpdf/Pl_OStream.cc | 2 +- libqpdf/Pl_PNGFilter.cc | 10 +++--- libqpdf/Pl_QPDFTokenizer.cc | 5 +-- libqpdf/Pl_RC4.cc | 4 +-- libqpdf/Pl_StdioFile.cc | 2 +- libqpdf/QPDF.cc | 8 ++--- libqpdf/QPDFArgParser.cc | 4 +-- libqpdf/QPDFCrypto_native.cc | 6 ++-- libqpdf/QPDFFormFieldObjectHelper.cc | 4 +-- libqpdf/QPDFJob.cc | 38 +++++++++++---------- libqpdf/QPDFJob_config.cc | 10 +++--- libqpdf/QPDFObject.cc | 6 ++-- libqpdf/QPDFObjectHandle.cc | 24 +++++++------- libqpdf/QPDFOutlineDocumentHelper.cc | 2 +- libqpdf/QPDFPageLabelDocumentHelper.cc | 2 +- libqpdf/QPDFTokenizer.cc | 8 ++--- libqpdf/QPDFWriter.cc | 46 +++++++++++++------------- libqpdf/QPDF_Dictionary.cc | 2 +- libqpdf/QPDF_Stream.cc | 10 +++--- libqpdf/QPDF_encryption.cc | 6 ++-- libqpdf/QPDF_linearization.cc | 2 +- libqpdf/QUtil.cc | 34 +++++++++---------- libqpdf/qpdf-c.cc | 34 +++++++++---------- 49 files changed, 193 insertions(+), 187 deletions(-) diff --git a/examples/pdf-attach-file.cc b/examples/pdf-attach-file.cc index eb12a002..c04f5b9f 100644 --- a/examples/pdf-attach-file.cc +++ b/examples/pdf-attach-file.cc @@ -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) @@ -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) { diff --git a/examples/pdf-bookmarks.cc b/examples/pdf-bookmarks.cc index f6c91b21..1cee51ef 100644 --- a/examples/pdf-bookmarks.cc +++ b/examples/pdf-bookmarks.cc @@ -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; diff --git a/examples/pdf-count-strings.cc b/examples/pdf-count-strings.cc index 85e05a5f..c762e7f8 100644 --- a/examples/pdf-count-strings.cc +++ b/examples/pdf-count-strings.cc @@ -15,7 +15,7 @@ #include #include -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc index 785021da..f730b743 100644 --- a/examples/pdf-create.cc +++ b/examples/pdf-create.cc @@ -20,7 +20,7 @@ #include #include -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. diff --git a/examples/pdf-custom-filter.cc b/examples/pdf-custom-filter.cc index e7877bea..2ea5fd42 100644 --- a/examples/pdf-custom-filter.cc +++ b/examples/pdf-custom-filter.cc @@ -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 { @@ -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) { diff --git a/examples/pdf-double-page-size.cc b/examples/pdf-double-page-size.cc index f0f86d02..fb0584e9 100644 --- a/examples/pdf-double-page-size.cc +++ b/examples/pdf-double-page-size.cc @@ -8,7 +8,7 @@ #include #include -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() diff --git a/examples/pdf-filter-tokens.cc b/examples/pdf-filter-tokens.cc index ccacc8c2..c9a71e64 100644 --- a/examples/pdf-filter-tokens.cc +++ b/examples/pdf-filter-tokens.cc @@ -18,7 +18,7 @@ #include #include -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() diff --git a/examples/pdf-invert-images.cc b/examples/pdf-invert-images.cc index 94392ac3..9ffb9c1f 100644 --- a/examples/pdf-invert-images.cc +++ b/examples/pdf-invert-images.cc @@ -9,7 +9,7 @@ #include #include -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() @@ -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)) { diff --git a/examples/pdf-mod-info.cc b/examples/pdf-mod-info.cc index 2b8e3c47..fa49738b 100644 --- a/examples/pdf-mod-info.cc +++ b/examples/pdf-mod-info.cc @@ -11,7 +11,7 @@ #include static char const* version = "1.1"; -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() @@ -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) { diff --git a/examples/pdf-name-number-tree.cc b/examples/pdf-name-number-tree.cc index 939105e9..381085ba 100644 --- a/examples/pdf-name-number-tree.cc +++ b/examples/pdf-name-number-tree.cc @@ -6,7 +6,7 @@ #include #include -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() diff --git a/examples/pdf-npages.cc b/examples/pdf-npages.cc index f430935c..3d34d489 100644 --- a/examples/pdf-npages.cc +++ b/examples/pdf-npages.cc @@ -5,7 +5,7 @@ #include #include -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() diff --git a/examples/pdf-overlay-page.cc b/examples/pdf-overlay-page.cc index 594f139e..d055d279 100644 --- a/examples/pdf-overlay-page.cc +++ b/examples/pdf-overlay-page.cc @@ -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() diff --git a/examples/pdf-parse-content.cc b/examples/pdf-parse-content.cc index 6bc94da2..481633e6 100644 --- a/examples/pdf-parse-content.cc +++ b/examples/pdf-parse-content.cc @@ -8,7 +8,7 @@ #include #include -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() diff --git a/examples/pdf-set-form-values.cc b/examples/pdf-set-form-values.cc index cc328cf3..1398c0dd 100644 --- a/examples/pdf-set-form-values.cc +++ b/examples/pdf-set-form-values.cc @@ -8,7 +8,7 @@ #include #include -static char const* whoami = 0; +static char const* whoami = nullptr; void usage() diff --git a/examples/qpdf-job.cc b/examples/qpdf-job.cc index b71b612a..614abbe6 100644 --- a/examples/qpdf-job.cc +++ b/examples/qpdf-job.cc @@ -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() diff --git a/libqpdf/Buffer.cc b/libqpdf/Buffer.cc index 91bacc8e..4e8a17ae 100644 --- a/libqpdf/Buffer.cc +++ b/libqpdf/Buffer.cc @@ -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; } @@ -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)) { } @@ -52,7 +52,8 @@ void Buffer::copy(Buffer const& rhs) { if (this != &rhs) { - this->m = std::shared_ptr(new Members(rhs.m->size, 0, true)); + this->m = + std::shared_ptr(new Members(rhs.m->size, nullptr, true)); if (this->m->size) { memcpy(this->m->buf, rhs.m->buf, this->m->size); } diff --git a/libqpdf/BufferInputSource.cc b/libqpdf/BufferInputSource.cc index 033ef265..5b59c801 100644 --- a/libqpdf/BufferInputSource.cc +++ b/libqpdf/BufferInputSource.cc @@ -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()); diff --git a/libqpdf/ClosedFileInputSource.cc b/libqpdf/ClosedFileInputSource.cc index 7d49bf70..dfb98c6a 100644 --- a/libqpdf/ClosedFileInputSource.cc +++ b/libqpdf/ClosedFileInputSource.cc @@ -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(this->m->filename.c_str()); this->m->fis->seek(this->m->offset, SEEK_SET); @@ -39,7 +39,7 @@ ClosedFileInputSource::after() if (this->m->stay_open) { return; } - this->m->fis = 0; + this->m->fis = nullptr; } qpdf_offset_t diff --git a/libqpdf/FileInputSource.cc b/libqpdf/FileInputSource.cc index 08b35056..ab88d302 100644 --- a/libqpdf/FileInputSource.cc +++ b/libqpdf/FileInputSource.cc @@ -7,7 +7,7 @@ FileInputSource::Members::Members(bool close_file) : close_file(close_file), - file(0) + file(nullptr) { } diff --git a/libqpdf/InputSource.cc b/libqpdf/InputSource.cc index ba4c3cbc..33ab44d1 100644 --- a/libqpdf/InputSource.cc +++ b/libqpdf/InputSource.cc @@ -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; @@ -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", @@ -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]"); } diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 8f4e75a2..1796c859 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -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); @@ -270,7 +270,7 @@ JSON JSON::addDictionaryMember(std::string const& key, JSON const& val) { JSON_dictionary* obj = dynamic_cast(this->m->value.get()); - if (0 == obj) { + if (nullptr == obj) { throw std::runtime_error( "JSON::addDictionaryMember called on non-dictionary"); } @@ -286,7 +286,7 @@ bool JSON::checkDictionaryKeySeen(std::string const& key) { JSON_dictionary* obj = dynamic_cast(this->m->value.get()); - if (0 == obj) { + if (nullptr == obj) { throw std::logic_error( "JSON::checkDictionaryKey called on non-dictionary"); } @@ -307,7 +307,7 @@ JSON JSON::addArrayElement(JSON const& val) { JSON_array* arr = dynamic_cast(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()) { diff --git a/libqpdf/Pipeline.cc b/libqpdf/Pipeline.cc index 5bd4557d..6f3f33db 100644 --- a/libqpdf/Pipeline.cc +++ b/libqpdf/Pipeline.cc @@ -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"); diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc index 829d0e7c..c7e3f923 100644 --- a/libqpdf/Pl_Buffer.cc +++ b/libqpdf/Pl_Buffer.cc @@ -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(len); } size_t cur_size = this->m->data->getSize(); diff --git a/libqpdf/Pl_Discard.cc b/libqpdf/Pl_Discard.cc index 4e0da6fc..f1078e3a 100644 --- a/libqpdf/Pl_Discard.cc +++ b/libqpdf/Pl_Discard.cc @@ -3,7 +3,7 @@ // Exercised in md5 test suite Pl_Discard::Pl_Discard() : - Pipeline("discard", 0) + Pipeline("discard", nullptr) { } diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc index 3ce7f434..4183b7e4 100644 --- a/libqpdf/Pl_Flate.cc +++ b/libqpdf/Pl_Flate.cc @@ -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(out_bufsize); // Indirect through zdata to reach the z_stream so we don't have @@ -29,10 +29,10 @@ Pl_Flate::Members::Members(size_t out_bufsize, action_e action) : } z_stream& zstream = *(static_cast(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); @@ -50,7 +50,7 @@ Pl_Flate::Members::~Members() } delete static_cast(this->zdata); - this->zdata = 0; + this->zdata = nullptr; } Pl_Flate::Pl_Flate( @@ -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"); @@ -227,7 +227,7 @@ Pl_Flate::finish() checkError("End", err); } - this->m->outbuf = 0; + this->m->outbuf = nullptr; } } catch (std::exception& e) { try { diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc index 3a381899..7d02f291 100644 --- a/libqpdf/Pl_LZWDecoder.cc +++ b/libqpdf/Pl_LZWDecoder.cc @@ -14,7 +14,7 @@ Pl_LZWDecoder::Pl_LZWDecoder( byte_pos(0), bit_pos(0), bits_available(0), - code_change_delta(early_code_change ? 1 : 0), + code_change_delta(early_code_change), eod(false), last_code(256) { @@ -107,7 +107,7 @@ void Pl_LZWDecoder::addToTable(unsigned char next) { unsigned int last_size = 0; - unsigned char const* last_data = 0; + unsigned char const* last_data = nullptr; unsigned char tmp[1]; if (this->last_code < 256) { diff --git a/libqpdf/Pl_OStream.cc b/libqpdf/Pl_OStream.cc index db0081df..137b6654 100644 --- a/libqpdf/Pl_OStream.cc +++ b/libqpdf/Pl_OStream.cc @@ -10,7 +10,7 @@ Pl_OStream::Members::Members(std::ostream& os) : } Pl_OStream::Pl_OStream(char const* identifier, std::ostream& os) : - Pipeline(identifier, 0), + Pipeline(identifier, nullptr), m(new Members(os)) { } diff --git a/libqpdf/Pl_PNGFilter.cc b/libqpdf/Pl_PNGFilter.cc index 7914b3b6..e2a9a0db 100644 --- a/libqpdf/Pl_PNGFilter.cc +++ b/libqpdf/Pl_PNGFilter.cc @@ -22,10 +22,10 @@ Pl_PNGFilter::Pl_PNGFilter( unsigned int bits_per_sample) : Pipeline(identifier, next), action(action), - cur_row(0), - prev_row(0), - buf1(0), - buf2(0), + cur_row(nullptr), + prev_row(nullptr), + buf1(nullptr), + buf2(nullptr), pos(0) { if (samples_per_pixel < 1) { @@ -243,7 +243,7 @@ Pl_PNGFilter::finish() // write partial row processRow(); } - this->prev_row = 0; + this->prev_row = nullptr; this->cur_row = buf1.get(); this->pos = 0; memset(this->cur_row, 0, this->bytes_per_row + 1); diff --git a/libqpdf/Pl_QPDFTokenizer.cc b/libqpdf/Pl_QPDFTokenizer.cc index 85b5fcce..9082538d 100644 --- a/libqpdf/Pl_QPDFTokenizer.cc +++ b/libqpdf/Pl_QPDFTokenizer.cc @@ -7,7 +7,7 @@ #include Pl_QPDFTokenizer::Members::Members() : - filter(0), + filter(nullptr), buf("tokenizer buffer") { } @@ -68,7 +68,8 @@ Pl_QPDFTokenizer::finish() } } this->m->filter->handleEOF(); - QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(m->filter, 0); + QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline( + m->filter, nullptr); Pipeline* next = this->getNext(true); if (next) { next->finish(); diff --git a/libqpdf/Pl_RC4.cc b/libqpdf/Pl_RC4.cc index 1f64b5d3..823b22ea 100644 --- a/libqpdf/Pl_RC4.cc +++ b/libqpdf/Pl_RC4.cc @@ -18,7 +18,7 @@ Pl_RC4::Pl_RC4( void Pl_RC4::write(unsigned char const* data, size_t len) { - if (this->outbuf.get() == 0) { + if (this->outbuf.get() == nullptr) { throw std::logic_error( this->identifier + ": Pl_RC4: write() called after finish() called"); @@ -41,6 +41,6 @@ Pl_RC4::write(unsigned char const* data, size_t len) void Pl_RC4::finish() { - this->outbuf = 0; + this->outbuf = nullptr; this->getNext()->finish(); } diff --git a/libqpdf/Pl_StdioFile.cc b/libqpdf/Pl_StdioFile.cc index 2415ef96..dca16bf6 100644 --- a/libqpdf/Pl_StdioFile.cc +++ b/libqpdf/Pl_StdioFile.cc @@ -12,7 +12,7 @@ Pl_StdioFile::Members::Members(FILE* f) : } Pl_StdioFile::Pl_StdioFile(char const* identifier, FILE* f) : - Pipeline(identifier, 0), + Pipeline(identifier, nullptr), m(new Members(f)) { } diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index a0f0f9e1..c2c764db 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -216,7 +216,7 @@ QPDF::Members::Members() : pushed_inherited_attributes_to_pages(false), ever_pushed_inherited_attributes_to_pages(false), ever_called_get_all_pages(false), - copied_stream_data_provider(0), + copied_stream_data_provider(nullptr), reconstructed_xref(false), fixed_dangling_refs(false), immediate_copy_from(false), @@ -1496,7 +1496,7 @@ QPDF::readObject( bool empty = false; std::shared_ptr decrypter_ph; - StringDecrypter* decrypter = 0; + StringDecrypter* decrypter = nullptr; if (this->m->encp->encrypted && (!in_object_stream)) { decrypter_ph = std::make_shared(this, og); decrypter = decrypter_ph.get(); @@ -2434,7 +2434,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) QPDFObjectHandle dict = result.getDict(); QPDFObjectHandle old_dict = foreign.getDict(); - if (this->m->copied_stream_data_provider == 0) { + if (this->m->copied_stream_data_provider == nullptr) { this->m->copied_stream_data_provider = new CopiedStreamDataProvider(*this); this->m->copied_streams = @@ -2457,7 +2457,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) } std::shared_ptr stream_buffer = stream->getStreamDataBuffer(); if ((foreign_stream_qpdf->m->immediate_copy_from) && - (stream_buffer.get() == 0)) { + (stream_buffer.get() == nullptr)) { // Pull the stream data into a buffer before attempting // the copy operation. Do it on the source stream so that // if the source stream is copied multiple times, we don't diff --git a/libqpdf/QPDFArgParser.cc b/libqpdf/QPDFArgParser.cc index c58edec7..89bf5ad1 100644 --- a/libqpdf/QPDFArgParser.cc +++ b/libqpdf/QPDFArgParser.cc @@ -30,7 +30,7 @@ QPDFArgParser::QPDFArgParser( m(new Members(argc, argv, progname_env)) { selectHelpOptionTable(); - char const* help_choices[] = {"all", 0}; + char const* help_choices[] = {"all", nullptr}; // More help choices are added dynamically. addChoices( "help", bindParam(&QPDFArgParser::argHelp, this), false, help_choices); @@ -254,7 +254,7 @@ QPDFArgParser::handleArgFileArguments() // deleted by using shared pointers to back the pointers in argv. this->m->new_argv.push_back(QUtil::make_shared_cstr(this->m->argv[0])); for (int i = 1; i < this->m->argc; ++i) { - char const* argfile = 0; + char const* argfile = nullptr; if ((strlen(this->m->argv[i]) > 1) && (this->m->argv[i][0] == '@')) { argfile = 1 + this->m->argv[i]; if (strcmp(argfile, "-") != 0) { diff --git a/libqpdf/QPDFCrypto_native.cc b/libqpdf/QPDFCrypto_native.cc index 458e90cb..5cd3c887 100644 --- a/libqpdf/QPDFCrypto_native.cc +++ b/libqpdf/QPDFCrypto_native.cc @@ -14,7 +14,7 @@ getRandomProvider() static RandomDataProvider* insecure_random_data_provider = InsecureRandomDataProvider::getInstance(); #else - static RandomDataProvider* insecure_random_data_provider = 0; + static RandomDataProvider* insecure_random_data_provider = nullptr; #endif static RandomDataProvider* secure_random_data_provider = SecureRandomDataProvider::getInstance(); @@ -22,9 +22,9 @@ getRandomProvider() static RandomDataProvider* provider = (secure_random_data_provider ? secure_random_data_provider : insecure_random_data_provider ? insecure_random_data_provider - : 0); + : nullptr); - if (provider == 0) { + if (provider == nullptr) { throw std::logic_error("QPDFCrypto_native has no random data provider"); } diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index 6373f04f..5ff41edd 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -746,7 +746,7 @@ TfFinder::handleToken(QPDFTokenizer::Token const& token) switch (ttype) { case QPDFTokenizer::tt_integer: case QPDFTokenizer::tt_real: - last_num = strtod(value.c_str(), 0); + last_num = strtod(value.c_str(), nullptr); last_num_idx = QIntC::to_int(DA.size() - 1); break; @@ -785,7 +785,7 @@ TfFinder::getDA() for (size_t i = 0; i < n; ++i) { std::string cur = this->DA.at(i); if (QIntC::to_int(i) == tf_idx) { - double delta = strtod(cur.c_str(), 0) - this->tf; + double delta = strtod(cur.c_str(), nullptr) - this->tf; if ((delta > 0.001) || (delta < -0.001)) { // tf doesn't match the font size passed to Tf, so // substitute. diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 343fa348..26425def 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -211,7 +211,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) bool ImageOptimizer::evaluate(std::string const& description) { - if (!image.pipeStreamData(0, 0, qpdf_dl_specialized, true)) { + if (!image.pipeStreamData(nullptr, 0, qpdf_dl_specialized, true)) { QTC::TC("qpdf", "QPDFJob image optimize no pipeline"); o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { v << prefix << ": " << description @@ -317,7 +317,7 @@ QPDFJob::Members::Members() : warnings(false), encryption_status(0), verbose(false), - password(0), + password(nullptr), linearize(false), decrypt(false), split_pages(0), @@ -326,7 +326,7 @@ QPDFJob::Members::Members() : suppress_warnings(false), warnings_exit_zero(false), copy_encryption(false), - encryption_file_password(0), + encryption_file_password(nullptr), encrypt(false), password_is_hex_key(false), suppress_password_recovery(false), @@ -411,7 +411,7 @@ QPDFJob::Members::Members() : ii_min_bytes(DEFAULT_II_MIN_BYTES), underlay("underlay"), overlay("overlay"), - under_overlay(0), + under_overlay(nullptr), require_outfile(true), replace_input(false), check_is_encrypted(false), @@ -673,13 +673,15 @@ QPDFJob::checkConfiguration() usage("--split-pages may not be used with --replace-input"); } } - if (m->infilename == 0) { + if (m->infilename == nullptr) { usage("an input file name is required"); } else if ( - m->require_outfile && (m->outfilename == 0) && (!m->replace_input)) { + m->require_outfile && (m->outfilename == nullptr) && + (!m->replace_input)) { usage("an output file name is required; use - for standard output"); } else if ( - (!m->require_outfile) && ((m->outfilename != 0) || m->replace_input)) { + (!m->require_outfile) && + ((m->outfilename != nullptr) || m->replace_input)) { usage("no output file may be given for this option"); } if (m->check_requires_password && m->check_is_encrypted) { @@ -924,7 +926,7 @@ QPDFJob::doShowObj(QPDF& pdf) if (obj.isStream()) { if (m->show_raw_stream_data || m->show_filtered_stream_data) { bool filter = m->show_filtered_stream_data; - if (filter && (!obj.pipeStreamData(0, 0, qpdf_dl_all))) { + if (filter && (!obj.pipeStreamData(nullptr, 0, qpdf_dl_all))) { QTC::TC("qpdf", "QPDFJob unable to filter"); obj.warnIfPossible("unable to filter stream data"); error = true; @@ -1204,7 +1206,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) j_image.addDictionaryMember( "filterable", JSON::makeBool( - image.pipeStreamData(0, 0, m->decode_level, true))); + image.pipeStreamData(nullptr, 0, m->decode_level, true))); } j_page.addDictionaryMember("images", j_images); JSON j_contents = @@ -1561,7 +1563,7 @@ QPDFJob::json_schema(int json_version, std::set* keys) "decodelevel": "decode level used to determine stream filterability" })")); - bool all_keys = ((keys == 0) || keys->empty()); + bool all_keys = ((keys == nullptr) || keys->empty()); // The list of selectable top-level keys id duplicated in the // following places: job.yml, QPDFJob::json_schema, and @@ -1943,7 +1945,7 @@ QPDFJob::doProcess( password = ptemp.c_str(); } } - if ((password == 0) || empty || m->password_is_hex_key || + if ((password == nullptr) || empty || m->password_is_hex_key || m->suppress_password_recovery) { // There is no password, or we're not doing recovery, so just // do the normal processing with the supplied password. @@ -2591,7 +2593,7 @@ QPDFJob::handlePageSpecs( // to the same underlying file with the same path to // achieve the same affect. char const* password = page_spec.password.get(); - if ((!m->encryption_file.empty()) && (password == 0) && + if ((!m->encryption_file.empty()) && (password == nullptr) && (page_spec.filename == m->encryption_file)) { QTC::TC("qpdf", "QPDFJob pages encryption password"); password = m->encryption_file_password.get(); @@ -2600,7 +2602,7 @@ QPDFJob::handlePageSpecs( v << prefix << ": processing " << page_spec.filename << "\n"; }); std::shared_ptr is; - ClosedFileInputSource* cis = 0; + ClosedFileInputSource* cis = nullptr; if (!m->keep_files_open) { QTC::TC("qpdf", "QPDFJob keep files open n"); cis = new ClosedFileInputSource(page_spec.filename.c_str()); @@ -2636,7 +2638,7 @@ QPDFJob::handlePageSpecs( if (m->remove_unreferenced_page_resources != QPDFJob::re_no) { for (auto const& iter: page_spec_qpdfs) { std::string const& filename = iter.first; - ClosedFileInputSource* cis = 0; + ClosedFileInputSource* cis = nullptr; if (page_spec_cfis.count(filename)) { cis = page_spec_cfis[filename]; cis->stayOpen(true); @@ -2707,7 +2709,7 @@ QPDFJob::handlePageSpecs( auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf); std::set referenced_fields; for (auto& page_data: parsed_specs) { - ClosedFileInputSource* cis = 0; + ClosedFileInputSource* cis = nullptr; if (page_spec_cfis.count(page_data.filename)) { cis = page_spec_cfis[page_data.filename]; cis->stayOpen(true); @@ -3061,7 +3063,7 @@ parse_version( auto vp = QUtil::make_unique_cstr(full_version_string); char* v = vp.get(); char* p1 = strchr(v, '.'); - char* p2 = (p1 ? strchr(1 + p1, '.') : 0); + char* p2 = (p1 ? strchr(1 + p1, '.') : nullptr); if (p2 && *(p2 + 1)) { *p2++ = '\0'; extension_level = QUtil::string_to_int(p2); @@ -3176,7 +3178,7 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) std::string after; size_t len = strlen(m->outfilename.get()); char* num_spot = strstr(const_cast(m->outfilename.get()), "%d"); - if (num_spot != 0) { + if (num_spot != nullptr) { QTC::TC("qpdf", "QPDFJob split-pages %d"); before = std::string( m->outfilename.get(), @@ -3310,7 +3312,7 @@ QPDFJob::writeOutfile(QPDF& pdf) }); } if (m->replace_input) { - m->outfilename = 0; + m->outfilename = nullptr; } if (m->replace_input) { // We must close the input before we can rename files diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index b9b53ebd..0192346e 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -13,7 +13,7 @@ QPDFJob::Config::checkConfiguration() QPDFJob::Config* QPDFJob::Config::inputFile(std::string const& filename) { - if (o.m->infilename == 0) { + if (o.m->infilename == nullptr) { o.m->infilename = QUtil::make_shared_cstr(filename); } else { usage("input file has already been given"); @@ -24,7 +24,7 @@ QPDFJob::Config::inputFile(std::string const& filename) QPDFJob::Config* QPDFJob::Config::emptyInput() { - if (o.m->infilename == 0) { + if (o.m->infilename == nullptr) { // Various places in QPDFJob.cc know that the empty string for // infile means empty. We set it to something other than a // null pointer as an indication that some input source has @@ -44,7 +44,7 @@ QPDFJob::Config::emptyInput() QPDFJob::Config* QPDFJob::Config::outputFile(std::string const& filename) { - if ((o.m->outfilename == 0) && (!o.m->replace_input)) { + if ((o.m->outfilename == nullptr) && (!o.m->replace_input)) { o.m->outfilename = QUtil::make_shared_cstr(filename); } else { usage("output file has already been given"); @@ -55,7 +55,7 @@ QPDFJob::Config::outputFile(std::string const& filename) QPDFJob::Config* QPDFJob::Config::replaceInput() { - if ((o.m->outfilename == 0) && (!o.m->replace_input)) { + if ((o.m->outfilename == nullptr) && (!o.m->replace_input)) { o.m->replace_input = true; } else { usage("replace-input can't be used" @@ -977,7 +977,7 @@ QPDFJob::UOConfig::endUnderlayOverlay() if (config->o.m->under_overlay->filename.empty()) { usage(config->o.m->under_overlay->which + " file not specified"); } - config->o.m->under_overlay = 0; + config->o.m->under_overlay = nullptr; return this->config; } diff --git a/libqpdf/QPDFObject.cc b/libqpdf/QPDFObject.cc index 39a5fa50..382dd6c6 100644 --- a/libqpdf/QPDFObject.cc +++ b/libqpdf/QPDFObject.cc @@ -1,7 +1,7 @@ #include QPDFObject::QPDFObject() : - owning_qpdf(0), + owning_qpdf(nullptr), parsed_offset(-1) { } @@ -25,13 +25,13 @@ QPDFObject::getDescription(QPDF*& qpdf, std::string& description) { qpdf = this->owning_qpdf; description = this->object_description; - return this->owning_qpdf != 0; + return this->owning_qpdf != nullptr; } bool QPDFObject::hasDescription() { - return this->owning_qpdf != 0; + return this->owning_qpdf != nullptr; } void diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 753493ec..bfbc19f9 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -265,7 +265,7 @@ QPDFObjectHandle::releaseResolved() // destruction. See comments in QPDF::~QPDF(). if (isIndirect()) { if (this->obj.get()) { - this->obj = 0; + this->obj = nullptr; } } else { QPDFObject::ObjAccessor::releaseResolved(this->obj.get()); @@ -780,7 +780,7 @@ QPDFObjectHandle::getArrayItem(int n) typeWarning("array", "returning null"); QTC::TC("qpdf", "QPDFObjectHandle array null for non-array"); } - QPDF* context = 0; + QPDF* context = nullptr; std::string description; if (this->obj->getDescription(context, description)) { result.setObjectDescription( @@ -998,7 +998,7 @@ QPDFObjectHandle::getKey(std::string const& key) typeWarning("dictionary", "returning null for attempted key retrieval"); QTC::TC("qpdf", "QPDFObjectHandle dictionary null for getKey"); result = newNull(); - QPDF* qpdf = 0; + QPDF* qpdf = nullptr; std::string description; if (this->obj->getDescription(qpdf, description)) { result.setObjectDescription( @@ -1655,7 +1655,7 @@ QPDFObjectHandle::coalesceContentStreams() return; } QPDF* qpdf = getOwningQPDF(); - if (qpdf == 0) { + if (qpdf == nullptr) { // Should not be possible for a page object to not have an // owning PDF unless it was manually constructed in some // incorrect way. However, it can happen in a PDF file whose @@ -1772,7 +1772,7 @@ QPDFObjectHandle::parse( QPDFTokenizer tokenizer; bool empty = false; QPDFObjectHandle result = - parse(input, object_description, tokenizer, empty, 0, context); + parse(input, object_description, tokenizer, empty, nullptr, context); size_t offset = QIntC::to_size(input->tell()); while (offset < object_str.length()) { if (!isspace(object_str.at(offset))) { @@ -1908,8 +1908,8 @@ QPDFObjectHandle::parseContentStream_data( tokenizer.readToken(input, "content", true); qpdf_offset_t offset = input->getLastOffset(); input->seek(offset, SEEK_SET); - QPDFObjectHandle obj = - parseInternal(input, "content", tokenizer, empty, 0, context, true); + QPDFObjectHandle obj = parseInternal( + input, "content", tokenizer, empty, nullptr, context, true); if (!obj.isInitialized()) { // EOF break; @@ -2185,7 +2185,7 @@ QPDFObjectHandle::parseInternal( (olist.at(olist.size() - 1).isInteger()) && (!olist.at(olist.size() - 2).isIndirect()) && (olist.at(olist.size() - 2).isInteger())) { - if (context == 0) { + if (context == nullptr) { QTC::TC( "qpdf", "QPDFObjectHandle indirect without context"); @@ -2661,7 +2661,7 @@ QPDFObjectHandle::newStream( QPDFObjectHandle QPDFObjectHandle::newStream(QPDF* qpdf) { - if (qpdf == 0) { + if (qpdf == nullptr) { throw std::runtime_error( "attempt to create stream in null qpdf object"); } @@ -2905,7 +2905,7 @@ QPDFObjectHandle::typeWarning( void QPDFObjectHandle::warnIfPossible(std::string const& warning) { - QPDF* context = 0; + QPDF* context = nullptr; std::string description; if (dereference() && obj->getDescription(context, description)) { warn(context, QPDFExc(qpdf_e_damaged_pdf, "", description, 0, warning)); @@ -3112,10 +3112,10 @@ QPDFObjectHandle::dereference() QPDF::Resolver::objectChanged(this->qpdf, getObjGen(), this->obj)) { this->obj = nullptr; } - if (this->obj.get() == 0) { + if (this->obj.get() == nullptr) { std::shared_ptr obj = QPDF::Resolver::resolve(this->qpdf, getObjGen()); - if (obj.get() == 0) { + if (obj.get() == nullptr) { // QPDF::resolve never returns an uninitialized object, but // check just in case. this->obj = QPDF_Null::create(); diff --git a/libqpdf/QPDFOutlineDocumentHelper.cc b/libqpdf/QPDFOutlineDocumentHelper.cc index 97189a23..4149ea1e 100644 --- a/libqpdf/QPDFOutlineDocumentHelper.cc +++ b/libqpdf/QPDFOutlineDocumentHelper.cc @@ -82,7 +82,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name) result = this->m->dest_dict.getKey(name.getName()); } } else if (name.isString()) { - if (0 == this->m->names_dest.get()) { + if (nullptr == this->m->names_dest.get()) { QPDFObjectHandle names = this->qpdf.getRoot().getKey("/Names"); if (names.isDictionary()) { QPDFObjectHandle dests = names.getKey("/Dests"); diff --git a/libqpdf/QPDFPageLabelDocumentHelper.cc b/libqpdf/QPDFPageLabelDocumentHelper.cc index babfd5aa..805dc40f 100644 --- a/libqpdf/QPDFPageLabelDocumentHelper.cc +++ b/libqpdf/QPDFPageLabelDocumentHelper.cc @@ -16,7 +16,7 @@ QPDFPageLabelDocumentHelper::QPDFPageLabelDocumentHelper(QPDF& qpdf) : bool QPDFPageLabelDocumentHelper::hasPageLabels() { - return 0 != this->m->labels.get(); + return nullptr != this->m->labels.get(); } QPDFObjectHandle diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc index d6467cc0..1726e1b9 100644 --- a/libqpdf/QPDFTokenizer.cc +++ b/libqpdf/QPDFTokenizer.cc @@ -17,7 +17,7 @@ static bool is_delimiter(char ch) { - return (strchr(" \t\n\v\f\r()<>[]{}/%", ch) != 0); + return (strchr(" \t\n\v\f\r()<>[]{}/%", ch) != nullptr); } namespace @@ -158,7 +158,7 @@ QPDFTokenizer::resolveLiteral() num[0] = this->m->val.at(i + 1); num[1] = this->m->val.at(i + 2); num[2] = '\0'; - char ch2 = static_cast(strtol(num, 0, 16)); + char ch2 = static_cast(strtol(num, nullptr, 16)); if (ch2 == '\0') { this->m->type = tt_bad; QTC::TC("qpdf", "QPDFTokenizer null in name"); @@ -323,7 +323,7 @@ QPDFTokenizer::presentCharacter(char ch) // We've accumulated \ddd. PDF Spec says to ignore // high-order overflow. this->m->val += - static_cast(strtol(this->m->bs_num_register, 0, 8)); + static_cast(strtol(this->m->bs_num_register, nullptr, 8)); memset( this->m->bs_num_register, '\0', @@ -447,7 +447,7 @@ QPDFTokenizer::presentCharacter(char ch) for (unsigned int i = 0; i < this->m->val.length(); i += 2) { num[0] = this->m->val.at(i); num[1] = this->m->val.at(i + 1); - char nch = static_cast(strtol(num, 0, 16)); + char nch = static_cast(strtol(num, nullptr, 16)); nval += nch; } this->m->val = nval; diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 50ec9406..b227e95a 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -52,10 +52,10 @@ QPDFWriter::FunctionProgressReporter::reportProgress(int progress) QPDFWriter::Members::Members(QPDF& pdf) : pdf(pdf), filename("unspecified"), - file(0), + file(nullptr), close_file(false), - buffer_pipeline(0), - output_buffer(0), + buffer_pipeline(nullptr), + output_buffer(nullptr), normalize_content_set(false), normalize_content(false), compress_streams(true), @@ -82,7 +82,7 @@ QPDFWriter::Members::Members(QPDF& pdf) : min_extension_level(0), forced_extension_level(0), encryption_dict_objid(0), - pipeline(0), + pipeline(nullptr), next_objid(1), cur_stream_length_id(0), cur_stream_length(0), @@ -90,7 +90,7 @@ QPDFWriter::Members::Members(QPDF& pdf) : max_ostream_index(0), next_stack_id(0), deterministic_id(false), - md5_pipeline(0), + md5_pipeline(nullptr), did_write_setup(false), events_expected(0), events_seen(0), @@ -128,9 +128,9 @@ void QPDFWriter::setOutputFilename(char const* filename) { char const* description = filename; - FILE* f = 0; + FILE* f = nullptr; bool close_file = false; - if (filename == 0) { + if (filename == nullptr) { description = "standard output"; QTC::TC("qpdf", "QPDFWriter write to stdout"); f = stdout; @@ -169,7 +169,7 @@ Buffer* QPDFWriter::getBuffer() { Buffer* result = this->m->output_buffer; - this->m->output_buffer = 0; + this->m->output_buffer = nullptr; return result; } @@ -1021,7 +1021,7 @@ QPDFWriter::writePad(int nspaces) Pipeline* QPDFWriter::pushPipeline(Pipeline* p) { - qpdf_assert_debug(dynamic_cast(p) == 0); + qpdf_assert_debug(dynamic_cast(p) == nullptr); this->m->pipeline_stack.push_back(p); return p; } @@ -1066,10 +1066,10 @@ QPDFWriter::PipelinePopper::~PipelinePopper() qpdf_assert_debug(qw->m->pipeline->getIdentifier() == stack_id); delete qw->m->pipeline_stack.back(); qw->m->pipeline_stack.pop_back(); - while (dynamic_cast(qw->m->pipeline_stack.back()) == 0) { + while (dynamic_cast(qw->m->pipeline_stack.back()) == nullptr) { Pipeline* p = qw->m->pipeline_stack.back(); if (dynamic_cast(p) == qw->m->md5_pipeline) { - qw->m->md5_pipeline = 0; + qw->m->md5_pipeline = nullptr; } qw->m->pipeline_stack.pop_back(); Pl_Buffer* buf = dynamic_cast(p); @@ -1097,7 +1097,7 @@ void QPDFWriter::pushEncryptionFilter(PipelinePopper& pp) { if (this->m->encrypted && (!this->m->cur_data_key.empty())) { - Pipeline* p = 0; + Pipeline* p = nullptr; if (this->m->encrypt_use_aes) { p = new Pl_AES_PDF( "aes stream encryption", @@ -1135,7 +1135,7 @@ QPDFWriter::pushMD5Pipeline(PipelinePopper& pp) " generation has already occurred."); } qpdf_assert_debug(this->m->deterministic_id); - qpdf_assert_debug(this->m->md5_pipeline == 0); + qpdf_assert_debug(this->m->md5_pipeline == nullptr); qpdf_assert_debug(this->m->pipeline->getCount() == 0); this->m->md5_pipeline = new Pl_MD5("qpdf md5", this->m->pipeline); this->m->md5_pipeline->persistAcrossFinish(true); @@ -1148,7 +1148,7 @@ QPDFWriter::pushMD5Pipeline(PipelinePopper& pp) void QPDFWriter::computeDeterministicIDData() { - qpdf_assert_debug(this->m->md5_pipeline != 0); + qpdf_assert_debug(this->m->md5_pipeline != nullptr); qpdf_assert_debug(this->m->deterministic_id_data.empty()); this->m->deterministic_id_data = this->m->md5_pipeline->getHexDigest(); this->m->md5_pipeline->enable(false); @@ -2455,10 +2455,10 @@ QPDFWriter::write() if (this->m->close_file) { fclose(this->m->file); } - this->m->file = 0; + this->m->file = nullptr; if (this->m->buffer_pipeline) { this->m->output_buffer = this->m->buffer_pipeline->getBuffer(); - this->m->buffer_pipeline = 0; + this->m->buffer_pipeline = nullptr; } indicateProgress(false, true); } @@ -2967,7 +2967,7 @@ QPDFWriter::writeLinearized() // Write file in two passes. Part numbers refer to PDF spec 1.4. - FILE* lin_pass1_file = 0; + FILE* lin_pass1_file = nullptr; auto pp_pass1 = std::make_shared(this); auto pp_md5 = std::make_shared(this); for (int pass = 1; pass <= 2; ++pass) { @@ -3203,13 +3203,13 @@ QPDFWriter::writeLinearized() "QPDFWriter linearized deterministic ID", need_xref_stream ? 0 : 1); computeDeterministicIDData(); - pp_md5 = 0; - qpdf_assert_debug(this->m->md5_pipeline == 0); + pp_md5 = nullptr; + qpdf_assert_debug(this->m->md5_pipeline == nullptr); } // Close first pass pipeline file_size = this->m->pipeline->getCount(); - pp_pass1 = 0; + pp_pass1 = nullptr; // Save hint offset since it will be set to zero by // calling openObject. @@ -3245,7 +3245,7 @@ QPDFWriter::writeLinearized() "%% second_xref_end=%s\n", QUtil::int_to_string(second_xref_end).c_str()); fclose(lin_pass1_file); - lin_pass1_file = 0; + lin_pass1_file = nullptr; } } } @@ -3401,7 +3401,7 @@ QPDFWriter::writeStandard() "qpdf", "QPDFWriter standard deterministic ID", this->m->object_stream_to_objects.empty() ? 0 : 1); - pp_md5 = 0; - qpdf_assert_debug(this->m->md5_pipeline == 0); + pp_md5 = nullptr; + qpdf_assert_debug(this->m->md5_pipeline == nullptr); } } diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index be3c5dcd..60b2339f 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -87,7 +87,7 @@ QPDF_Dictionary::getKey(std::string const& key) return item->second; } else { QPDFObjectHandle null = QPDFObjectHandle::newNull(); - QPDF* qpdf = 0; + QPDF* qpdf = nullptr; std::string description; if (getDescription(qpdf, description)) { null.setObjectDescription( diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 84965102..1b7f9461 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -169,7 +169,7 @@ QPDF_Stream::getFilterOnWrite() const void QPDF_Stream::releaseResolved() { - this->stream_provider = 0; + this->stream_provider = nullptr; QPDFObjectHandle::ReleaseResolver::releaseResolved(this->stream_dict); } @@ -313,7 +313,7 @@ QPDF_Stream::setDescription(QPDF* qpdf, std::string const& description) void QPDF_Stream::setDictDescription() { - QPDF* qpdf = 0; + QPDF* qpdf = nullptr; std::string description; if ((!this->stream_dict.hasObjectDescription()) && getDescription(qpdf, description)) { @@ -547,7 +547,7 @@ QPDF_Stream::pipeStreamData( : 3); } - if (pipeline == 0) { + if (pipeline == nullptr) { QTC::TC("qpdf", "QPDF_Stream pipeStreamData with null pipeline"); // Return value is whether we can filter in this case. return filter; @@ -693,7 +693,7 @@ QPDF_Stream::replaceStreamData( QPDFObjectHandle const& decode_parms) { this->stream_data = data; - this->stream_provider = 0; + this->stream_provider = nullptr; replaceFilterData(filter, decode_parms, data->getSize()); } @@ -704,7 +704,7 @@ QPDF_Stream::replaceStreamData( QPDFObjectHandle const& decode_parms) { this->stream_provider = provider; - this->stream_data = 0; + this->stream_data = nullptr; replaceFilterData(filter, decode_parms, 0); } diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 8c35b992..266907a8 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -149,8 +149,8 @@ QPDF::trim_user_password(std::string& user_password) } char const* p1 = cstr; - char const* p2 = 0; - while ((p2 = strchr(p1, '\x28')) != 0) { + char const* p2 = nullptr; + while ((p2 = strchr(p1, '\x28')) != nullptr) { size_t idx = toS(p2 - cstr); if (memcmp(p2, padding_string, len - idx) == 0) { user_password = user_password.substr(0, idx); @@ -218,7 +218,7 @@ process_with_aes( std::string const& data, size_t outlength = 0, unsigned int repetitions = 1, - unsigned char const* iv = 0, + unsigned char const* iv = nullptr, size_t iv_length = 0) { Pl_Buffer buffer("buffer"); diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 64805f58..f89ed188 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -542,7 +542,7 @@ QPDF::checkLinearizationInternal() // T: offset of whitespace character preceding xref entry for object 0 this->m->file->seek(p.xref_zero_offset, SEEK_SET); - while (1) { + while (true) { char ch; this->m->file->read(&ch, 1); if (!((ch == ' ') || (ch == '\r') || (ch == '\n'))) { diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 7a5d3caf..4e58aaf7 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -396,7 +396,7 @@ QUtil::string_to_ll(char const* str) #ifdef _MSC_VER long long result = _strtoi64(str, 0, 10); #else - long long result = strtoll(str, 0, 10); + long long result = strtoll(str, nullptr, 10); #endif if (errno == ERANGE) { throw std::range_error( @@ -430,7 +430,7 @@ QUtil::string_to_ull(char const* str) #ifdef _MSC_VER unsigned long long result = _strtoui64(str, 0, 10); #else - unsigned long long result = strtoull(str, 0, 10); + unsigned long long result = strtoull(str, nullptr, 10); #endif if (errno == ERANGE) { throw std::runtime_error( @@ -512,7 +512,7 @@ win_convert_filename(char const* filename) FILE* QUtil::safe_fopen(char const* filename, char const* mode) { - FILE* f = 0; + FILE* f = nullptr; #ifdef _WIN32 std::shared_ptr wfilenamep = win_convert_filename(filename); wchar_t* wfilename = wfilenamep.get(); @@ -543,7 +543,7 @@ QUtil::safe_fopen(char const* filename, char const* mode) FILE* QUtil::fopen_wrapper(std::string const& description, FILE* f) { - if (f == 0) { + if (f == nullptr) { throw_system_error(description); } return f; @@ -599,7 +599,7 @@ QUtil::tell(FILE* stream) bool QUtil::same_file(char const* name1, char const* name2) { - if ((name1 == 0) || (strlen(name1) == 0) || (name2 == 0) || + if ((name1 == nullptr) || (strlen(name1) == 0) || (name2 == nullptr) || (strlen(name2) == 0)) { return false; } @@ -834,7 +834,7 @@ QUtil::setLineBuf(FILE* f) char* QUtil::getWhoami(char* argv0) { - char* whoami = 0; + char* whoami = nullptr; if (((whoami = strrchr(argv0, '/')) == NULL) && ((whoami = strrchr(argv0, '\\')) == NULL)) { whoami = argv0; @@ -875,7 +875,7 @@ QUtil::get_env(std::string const& var, std::string* value) # endif #else char* p = getenv(var.c_str()); - if (p == 0) { + if (p == nullptr) { return false; } if (value) { @@ -908,7 +908,7 @@ QUtil::get_current_time() ULONGLONG now = uinow.QuadPart; return static_cast((now / 10000000ULL) - 11644473600ULL); #else - return time(0); + return time(nullptr); #endif } @@ -931,7 +931,7 @@ QUtil::get_current_qpdf_time() static_cast(tzinfo.Bias)); #else struct tm ltime; - time_t now = time(0); + time_t now = time(nullptr); tzset(); # ifdef HAVE_LOCALTIME_R localtime_r(&now, <ime); @@ -1155,7 +1155,7 @@ namespace RandomDataProviderProvider::RandomDataProviderProvider() : default_provider(CryptoRandomDataProvider::getInstance()), - current_provider(0) + current_provider(nullptr) { this->current_provider = default_provider; } @@ -1210,13 +1210,13 @@ QUtil::random() bool QUtil::is_hex_digit(char ch) { - return (ch && (strchr("0123456789abcdefABCDEF", ch) != 0)); + return (ch && (strchr("0123456789abcdefABCDEF", ch) != nullptr)); } bool QUtil::is_space(char ch) { - return (ch && (strchr(" \f\n\r\t\v", ch) != 0)); + return (ch && (strchr(" \f\n\r\t\v", ch) != nullptr)); } bool @@ -1332,10 +1332,10 @@ QUtil::read_lines_from_file( std::list& lines, bool preserve_eol) { - std::string* buf = 0; + std::string* buf = nullptr; char c; while (next_char(c)) { - if (buf == 0) { + if (buf == nullptr) { lines.push_back(""); buf = &(lines.back()); buf->reserve(80); @@ -1354,7 +1354,7 @@ QUtil::read_lines_from_file( buf->erase(buf->length() - 1); } } - buf = 0; + buf = nullptr; } else { buf->append(1, c); } @@ -1471,7 +1471,7 @@ QUtil::parse_numrange(char const* range, int max) } } - p = 0; + p = nullptr; for (size_t i = 0; i < work.size(); i += 2) { int num = work.at(i); // max == 0 means we don't know the max and are just @@ -1990,7 +1990,7 @@ call_main_from_wmain( new_argv[i] = utf8_argv.at(i).get(); } argc = QIntC::to_int(utf8_argv.size()); - new_argv[argc] = 0; + new_argv[argc] = nullptr; return realmain(argc, new_argv); } diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc index bde0ac72..390699db 100644 --- a/libqpdf/qpdf-c.cc +++ b/libqpdf/qpdf-c.cc @@ -164,7 +164,7 @@ qpdf_cleanup(qpdf_data* qpdf) << (*qpdf)->error->what() << "\n"; } delete *qpdf; - *qpdf = 0; + *qpdf = nullptr; } size_t @@ -203,11 +203,11 @@ qpdf_get_error(qpdf_data qpdf) { if (qpdf->error.get()) { qpdf->tmp_error.exc = qpdf->error; - qpdf->error = 0; + qpdf->error = nullptr; QTC::TC("qpdf", "qpdf-c qpdf_get_error returned error"); return &qpdf->tmp_error; } else { - return 0; + return nullptr; } } @@ -220,14 +220,14 @@ qpdf_next_warning(qpdf_data qpdf) QTC::TC("qpdf", "qpdf-c qpdf_next_warning returned warning"); return &qpdf->tmp_error; } else { - return 0; + return nullptr; } } char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e) { - if (e == 0) { + if (e == nullptr) { return ""; } return e->exc->what(); @@ -236,7 +236,7 @@ qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e) enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e) { - if (e == 0) { + if (e == nullptr) { return qpdf_e_success; } return e->exc->getErrorCode(); @@ -245,7 +245,7 @@ qpdf_get_error_code(qpdf_data qpdf, qpdf_error e) char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e) { - if (e == 0) { + if (e == nullptr) { return ""; } return e->exc->getFilename().c_str(); @@ -254,7 +254,7 @@ qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e) unsigned long long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e) { - if (e == 0) { + if (e == nullptr) { return 0; } return QIntC::to_ulonglong(e->exc->getFilePosition()); @@ -263,7 +263,7 @@ qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e) char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e) { - if (e == 0) { + if (e == nullptr) { return ""; } return e->exc->getMessageDetail().c_str(); @@ -371,7 +371,7 @@ qpdf_get_user_password(qpdf_data qpdf) char const* qpdf_get_info_key(qpdf_data qpdf, char const* key) { - char const* result = 0; + char const* result = nullptr; QPDFObjectHandle trailer = qpdf->qpdf->getTrailer(); if (trailer.hasKey("/Info")) { QPDFObjectHandle info = trailer.getKey("/Info"); @@ -383,14 +383,14 @@ qpdf_get_info_key(qpdf_data qpdf, char const* key) } } } - QTC::TC("qpdf", "qpdf-c get_info_key", (result == 0 ? 0 : 1)); + QTC::TC("qpdf", "qpdf-c get_info_key", (result == nullptr ? 0 : 1)); return result; } void qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value) { - if ((key == 0) || (std::strlen(key) == 0) || (key[0] != '/')) { + if ((key == nullptr) || (std::strlen(key) == 0) || (key[0] != '/')) { return; } QPDFObjectHandle value_object; @@ -498,11 +498,11 @@ qpdf_init_write_internal(qpdf_data qpdf) { if (qpdf->qpdf_writer.get()) { QTC::TC("qpdf", "qpdf-c called qpdf_init_write multiple times"); - qpdf->qpdf_writer = 0; + qpdf->qpdf_writer = nullptr; if (qpdf->output_buffer.get()) { - qpdf->output_buffer = 0; + qpdf->output_buffer = nullptr; qpdf->write_memory = false; - qpdf->filename = 0; + qpdf->filename = nullptr; } } } @@ -530,7 +530,7 @@ qpdf_init_write_memory(qpdf_data qpdf) static void qpdf_get_buffer_internal(qpdf_data qpdf) { - if (qpdf->write_memory && (qpdf->output_buffer == 0)) { + if (qpdf->write_memory && (qpdf->output_buffer == nullptr)) { qpdf->output_buffer = qpdf->qpdf_writer->getBufferSharedPointer(); } } @@ -549,7 +549,7 @@ qpdf_get_buffer_length(qpdf_data qpdf) unsigned char const* qpdf_get_buffer(qpdf_data qpdf) { - unsigned char const* result = 0; + unsigned char const* result = nullptr; qpdf_get_buffer_internal(qpdf); if (qpdf->output_buffer.get()) { result = qpdf->output_buffer->getBuffer();