diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc index a28a1a3..9a575ad 100644 --- a/libqpdf/Pl_Flate.cc +++ b/libqpdf/Pl_Flate.cc @@ -29,7 +29,7 @@ Pl_Flate::Members::Members(size_t out_bufsize, action_e action) : // Indirect through zdata to reach the z_stream so we don't have to include zlib.h in // Pl_Flate.hh. This means people using shared library versions of qpdf don't have to have zlib // development files available, which particularly helps in a Windows environment. - this->zdata = new z_stream; + zdata = new z_stream; if (out_bufsize > UINT_MAX) { throw std::runtime_error( @@ -52,8 +52,8 @@ Pl_Flate::Members::Members(size_t out_bufsize, action_e action) : Pl_Flate::Members::~Members() { - if (this->initialized) { - z_stream& zstream = *(static_cast(this->zdata)); + if (initialized) { + z_stream& zstream = *(static_cast(zdata)); if (action == a_deflate) { deflateEnd(&zstream); } else { @@ -62,7 +62,7 @@ Pl_Flate::Members::~Members() } delete static_cast(this->zdata); - this->zdata = nullptr; + zdata = nullptr; } Pl_Flate::Pl_Flate( @@ -99,7 +99,7 @@ Pl_Flate::setWarnCallback(std::function callback) void Pl_Flate::warn(char const* msg, int code) { - if (m->callback != nullptr) { + if (m->callback) { m->callback(msg, code); } } @@ -107,7 +107,7 @@ Pl_Flate::warn(char const* msg, int code) void Pl_Flate::write(unsigned char const* data, size_t len) { - if (m->outbuf == nullptr) { + if (!m->outbuf) { throw std::logic_error( this->identifier + ": Pl_Flate: write() called after finish() called"); } @@ -184,7 +184,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) // this error (including at least one in qpdf's test suite). In some cases, we want to // know about this, because it indicates incorrect compression, so call a callback if // provided. - this->warn("input stream is complete but output may still be valid", err); + warn("input stream is complete but output may still be valid", err); done = true; break; @@ -215,7 +215,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) break; default: - this->checkError("data", err); + checkError("data", err); break; } } @@ -271,7 +271,7 @@ Pl_Flate::checkError(char const* prefix, int error_code) z_stream& zstream = *(static_cast(m->zdata)); if (error_code != Z_OK) { char const* action_str = (m->action == a_deflate ? "deflate" : "inflate"); - std::string msg = this->identifier + ": " + action_str + ": " + prefix + ": "; + std::string msg = identifier + ": " + action_str + ": " + prefix + ": "; if (zstream.msg) { msg += zstream.msg; diff --git a/libqpdf/Pl_PNGFilter.cc b/libqpdf/Pl_PNGFilter.cc index e3930e2..e3a3528 100644 --- a/libqpdf/Pl_PNGFilter.cc +++ b/libqpdf/Pl_PNGFilter.cc @@ -39,7 +39,7 @@ Pl_PNGFilter::Pl_PNGFilter( throw std::runtime_error( "PNGFilter created with invalid bits_per_sample not 1, 2, 4, 8, or 16"); } - this->bytes_per_pixel = ((bits_per_sample * samples_per_pixel) + 7) / 8; + bytes_per_pixel = ((bits_per_sample * samples_per_pixel) + 7) / 8; unsigned long long bpr = ((columns * bits_per_sample * samples_per_pixel) + 7) / 8; if ((bpr == 0) || (bpr > (UINT_MAX - 1))) { throw std::runtime_error("PNGFilter created with invalid columns value"); @@ -47,16 +47,16 @@ Pl_PNGFilter::Pl_PNGFilter( if (memory_limit > 0 && bpr > (memory_limit / 2U)) { throw std::runtime_error("PNGFilter memory limit exceeded"); } - this->bytes_per_row = bpr & UINT_MAX; - this->buf1 = QUtil::make_shared_array(this->bytes_per_row + 1); - this->buf2 = QUtil::make_shared_array(this->bytes_per_row + 1); - memset(this->buf1.get(), 0, this->bytes_per_row + 1); - memset(this->buf2.get(), 0, this->bytes_per_row + 1); - this->cur_row = this->buf1.get(); - this->prev_row = this->buf2.get(); + bytes_per_row = bpr & UINT_MAX; + buf1 = QUtil::make_shared_array(bytes_per_row + 1); + buf2 = QUtil::make_shared_array(bytes_per_row + 1); + memset(buf1.get(), 0, bytes_per_row + 1); + memset(buf2.get(), 0, bytes_per_row + 1); + cur_row = buf1.get(); + prev_row = buf2.get(); // number of bytes per incoming row - this->incoming = (action == a_encode ? this->bytes_per_row : this->bytes_per_row + 1); + incoming = (action == a_encode ? bytes_per_row : bytes_per_row + 1); } void @@ -68,34 +68,34 @@ Pl_PNGFilter::setMemoryLimit(unsigned long long limit) void Pl_PNGFilter::write(unsigned char const* data, size_t len) { - size_t left = this->incoming - this->pos; + size_t left = incoming - pos; size_t offset = 0; while (len >= left) { // finish off current row - memcpy(this->cur_row + this->pos, data + offset, left); + memcpy(cur_row + pos, data + offset, left); offset += left; len -= left; processRow(); // Swap rows - unsigned char* t = this->prev_row; - this->prev_row = this->cur_row; - this->cur_row = t ? t : this->buf2.get(); - memset(this->cur_row, 0, this->bytes_per_row + 1); - left = this->incoming; - this->pos = 0; + unsigned char* t = prev_row; + prev_row = cur_row; + cur_row = t ? t : buf2.get(); + memset(cur_row, 0, bytes_per_row + 1); + left = incoming; + pos = 0; } if (len) { - memcpy(this->cur_row + this->pos, data + offset, len); + memcpy(cur_row + pos, data + offset, len); } - this->pos += len; + pos += len; } void Pl_PNGFilter::processRow() { - if (this->action == a_encode) { + if (action == a_encode) { encodeRow(); } else { decodeRow(); @@ -105,22 +105,22 @@ Pl_PNGFilter::processRow() void Pl_PNGFilter::decodeRow() { - int filter = this->cur_row[0]; - if (this->prev_row) { + int filter = cur_row[0]; + if (prev_row) { switch (filter) { case 0: break; case 1: - this->decodeSub(); + decodeSub(); break; case 2: - this->decodeUp(); + decodeUp(); break; case 3: - this->decodeAverage(); + decodeAverage(); break; case 4: - this->decodePaeth(); + decodePaeth(); break; default: // ignore @@ -128,17 +128,17 @@ Pl_PNGFilter::decodeRow() } } - next()->write(this->cur_row + 1, this->bytes_per_row); + next()->write(cur_row + 1, bytes_per_row); } void Pl_PNGFilter::decodeSub() { QTC::TC("libtests", "Pl_PNGFilter decodeSub"); - unsigned char* buffer = this->cur_row + 1; - unsigned int bpp = this->bytes_per_pixel; + unsigned char* buffer = cur_row + 1; + unsigned int bpp = bytes_per_pixel; - for (unsigned int i = 0; i < this->bytes_per_row; ++i) { + for (unsigned int i = 0; i < bytes_per_row; ++i) { unsigned char left = 0; if (i >= bpp) { @@ -153,10 +153,10 @@ void Pl_PNGFilter::decodeUp() { QTC::TC("libtests", "Pl_PNGFilter decodeUp"); - unsigned char* buffer = this->cur_row + 1; - unsigned char* above_buffer = this->prev_row + 1; + unsigned char* buffer = cur_row + 1; + unsigned char* above_buffer = prev_row + 1; - for (unsigned int i = 0; i < this->bytes_per_row; ++i) { + for (unsigned int i = 0; i < bytes_per_row; ++i) { unsigned char up = above_buffer[i]; buffer[i] = static_cast(buffer[i] + up); } @@ -166,11 +166,11 @@ void Pl_PNGFilter::decodeAverage() { QTC::TC("libtests", "Pl_PNGFilter decodeAverage"); - unsigned char* buffer = this->cur_row + 1; - unsigned char* above_buffer = this->prev_row + 1; - unsigned int bpp = this->bytes_per_pixel; + unsigned char* buffer = cur_row + 1; + unsigned char* above_buffer = prev_row + 1; + unsigned int bpp = bytes_per_pixel; - for (unsigned int i = 0; i < this->bytes_per_row; ++i) { + for (unsigned int i = 0; i < bytes_per_row; ++i) { int left = 0; int up = 0; @@ -187,11 +187,11 @@ void Pl_PNGFilter::decodePaeth() { QTC::TC("libtests", "Pl_PNGFilter decodePaeth"); - unsigned char* buffer = this->cur_row + 1; - unsigned char* above_buffer = this->prev_row + 1; - unsigned int bpp = this->bytes_per_pixel; + unsigned char* buffer = cur_row + 1; + unsigned char* above_buffer = prev_row + 1; + unsigned int bpp = bytes_per_pixel; - for (unsigned int i = 0; i < this->bytes_per_row; ++i) { + for (unsigned int i = 0; i < bytes_per_row; ++i) { int left = 0; int up = above_buffer[i]; int upper_left = 0; @@ -201,8 +201,7 @@ Pl_PNGFilter::decodePaeth() upper_left = above_buffer[i - bpp]; } - buffer[i] = - static_cast(buffer[i] + this->PaethPredictor(left, up, upper_left)); + buffer[i] = static_cast(buffer[i] + PaethPredictor(left, up, upper_left)); } } @@ -229,27 +228,27 @@ Pl_PNGFilter::encodeRow() // For now, hard-code to using UP filter. unsigned char ch = 2; next()->write(&ch, 1); - if (this->prev_row) { - for (unsigned int i = 0; i < this->bytes_per_row; ++i) { - ch = static_cast(this->cur_row[i] - this->prev_row[i]); + if (prev_row) { + for (unsigned int i = 0; i < bytes_per_row; ++i) { + ch = static_cast(cur_row[i] - prev_row[i]); next()->write(&ch, 1); } } else { - next()->write(this->cur_row, this->bytes_per_row); + next()->write(cur_row, bytes_per_row); } } void Pl_PNGFilter::finish() { - if (this->pos) { + if (pos) { // write partial row processRow(); } - this->prev_row = nullptr; - this->cur_row = buf1.get(); - this->pos = 0; - memset(this->cur_row, 0, this->bytes_per_row + 1); + prev_row = nullptr; + cur_row = buf1.get(); + pos = 0; + memset(cur_row, 0, bytes_per_row + 1); next()->finish(); } diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc index 180a7a6..f49b7b5 100644 --- a/libqpdf/QPDFJob_argv.cc +++ b/libqpdf/QPDFJob_argv.cc @@ -58,25 +58,25 @@ void ArgParser::initOptionTables() { #include - this->ap.addFinalCheck([this]() { c_main->checkConfiguration(); }); + ap.addFinalCheck([this]() { c_main->checkConfiguration(); }); // add_help is defined in auto_job_help.hh - add_help(this->ap); + add_help(ap); // Special case: ignore -- at the top level. This undocumented behavior is for backward // compatibility; it was unintentionally the case prior to 10.6, and some users were relying on // it. - this->ap.selectMainOptionTable(); - this->ap.addBare("--", []() {}); + ap.selectMainOptionTable(); + ap.addBare("--", []() {}); } void ArgParser::argPositional(std::string const& arg) { - if (!this->gave_input) { + if (!gave_input) { c_main->inputFile(arg); - this->gave_input = true; - } else if (!this->gave_output) { + gave_input = true; + } else if (!gave_output) { c_main->outputFile(arg); - this->gave_output = true; + gave_output = true; } else { usage("unknown argument " + arg); } @@ -86,20 +86,20 @@ void ArgParser::argEmpty() { c_main->emptyInput(); - this->gave_input = true; + gave_input = true; } void ArgParser::argReplaceInput() { c_main->replaceInput(); - this->gave_output = true; + gave_output = true; } void ArgParser::argVersion() { - auto whoami = this->ap.getProgname(); + auto whoami = ap.getProgname(); *QPDFLogger::defaultLogger()->getInfo() << whoami << " version " << QPDF::QPDFVersion() << "\n" << "Run " << whoami << " --copyright to see copyright and license information.\n"; @@ -136,7 +136,7 @@ ArgParser::argCopyright() // 1 2 3 4 5 6 7 8 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 *QPDFLogger::defaultLogger()->getInfo() - << this->ap.getProgname() + << ap.getProgname() << " version " << QPDF::QPDFVersion() << "\n" << "\n" << "Copyright (c) 2005-2021 Jay Berkenbilt\n" @@ -190,9 +190,9 @@ ArgParser::argShowCrypto() void ArgParser::argEncrypt() { - this->c_enc = c_main->encrypt(0, "", ""); - this->accumulated_args.clear(); - this->ap.selectOptionTable(O_ENCRYPTION); + c_enc = c_main->encrypt(0, "", ""); + accumulated_args.clear(); + ap.selectOptionTable(O_ENCRYPTION); } void @@ -202,14 +202,14 @@ ArgParser::argEncPositional(std::string const& arg) usage("positional and dashed encryption arguments may not be mixed"); } - this->accumulated_args.push_back(arg); - if (this->accumulated_args.size() < 3) { + accumulated_args.push_back(arg); + if (accumulated_args.size() < 3) { return; } - user_password = this->accumulated_args.at(0); - owner_password = this->accumulated_args.at(1); - auto len_str = this->accumulated_args.at(2); - this->accumulated_args.clear(); + user_password = accumulated_args.at(0); + owner_password = accumulated_args.at(1); + auto len_str = accumulated_args.at(2); + accumulated_args.clear(); argEncBits(len_str); } @@ -219,8 +219,8 @@ ArgParser::argEncUserPassword(std::string const& arg) if (!accumulated_args.empty()) { usage("positional and dashed encryption arguments may not be mixed"); } - this->used_enc_password_args = true; - this->user_password = arg; + used_enc_password_args = true; + user_password = arg; } void @@ -229,8 +229,8 @@ ArgParser::argEncOwnerPassword(std::string const& arg) if (!accumulated_args.empty()) { usage("positional and dashed encryption arguments may not be mixed"); } - this->used_enc_password_args = true; - this->owner_password = arg; + used_enc_password_args = true; + owner_password = arg; } void @@ -242,25 +242,25 @@ ArgParser::argEncBits(std::string const& arg) int keylen = 0; if (arg == "40") { keylen = 40; - this->ap.selectOptionTable(O_40_BIT_ENCRYPTION); + ap.selectOptionTable(O_40_BIT_ENCRYPTION); } else if (arg == "128") { keylen = 128; - this->ap.selectOptionTable(O_128_BIT_ENCRYPTION); + ap.selectOptionTable(O_128_BIT_ENCRYPTION); } else if (arg == "256") { keylen = 256; - this->ap.selectOptionTable(O_256_BIT_ENCRYPTION); + ap.selectOptionTable(O_256_BIT_ENCRYPTION); } else { usage("encryption key length must be 40, 128, or 256"); } - this->c_enc = c_main->encrypt(keylen, user_password, owner_password); + c_enc = c_main->encrypt(keylen, user_password, owner_password); } void ArgParser::argPages() { - this->accumulated_args.clear(); - this->c_pages = c_main->pages(); - this->ap.selectOptionTable(O_PAGES); + accumulated_args.clear(); + c_pages = c_main->pages(); + ap.selectOptionTable(O_PAGES); } void @@ -308,29 +308,29 @@ ArgParser::argEndPages() void ArgParser::argUnderlay() { - this->c_uo = c_main->underlay(); - this->ap.selectOptionTable(O_UNDERLAY_OVERLAY); + c_uo = c_main->underlay(); + ap.selectOptionTable(O_UNDERLAY_OVERLAY); } void ArgParser::argOverlay() { - this->c_uo = c_main->overlay(); - this->ap.selectOptionTable(O_UNDERLAY_OVERLAY); + c_uo = c_main->overlay(); + ap.selectOptionTable(O_UNDERLAY_OVERLAY); } void ArgParser::argAddAttachment() { - this->c_att = c_main->addAttachment(); - this->ap.selectOptionTable(O_ATTACHMENT); + c_att = c_main->addAttachment(); + ap.selectOptionTable(O_ATTACHMENT); } void ArgParser::argCopyAttachmentsFrom() { - this->c_copy_att = c_main->copyAttachmentsFrom(); - this->ap.selectOptionTable(O_COPY_ATTACHMENT); + c_copy_att = c_main->copyAttachmentsFrom(); + ap.selectOptionTable(O_COPY_ATTACHMENT); } void @@ -400,7 +400,7 @@ ArgParser::argEndCopyAttachment() void ArgParser::argSetPageLabels() { - this->ap.selectOptionTable(O_SET_PAGE_LABELS); + ap.selectOptionTable(O_SET_PAGE_LABELS); accumulated_args.clear(); } @@ -427,14 +427,14 @@ ArgParser::argJobJsonHelp() void ArgParser::usage(std::string const& message) { - this->ap.usage(message); + ap.usage(message); } void ArgParser::parseOptions() { try { - this->ap.parseArgs(); + ap.parseArgs(); } catch (std::runtime_error& e) { usage(e.what()); } diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index f4f2f36..f94d52d 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -701,7 +701,7 @@ QPDFJob::Config::passwordFile(std::string const& parameter) if (lines.size() > 1) { *QPDFLogger::defaultLogger()->getError() - << this->o.m->message_prefix << ": WARNING: all but the first line of" + << o.m->message_prefix << ": WARNING: all but the first line of" << " the password file are ignored\n"; } } @@ -806,7 +806,7 @@ QPDFJob::Config::jobJsonFile(std::string const& parameter) } catch (std::exception& e) { throw std::runtime_error( "error with job-json file " + std::string(parameter) + ": " + e.what() + "\nRun " + - this->o.m->message_prefix + " --job-json-help for information on the file format."); + o.m->message_prefix + " --job-json-help for information on the file format."); } return this; } @@ -832,32 +832,32 @@ QPDFJob::CopyAttConfig::CopyAttConfig(Config* c) : QPDFJob::CopyAttConfig* QPDFJob::CopyAttConfig::file(std::string const& parameter) { - this->caf.path = parameter; + caf.path = parameter; return this; } QPDFJob::CopyAttConfig* QPDFJob::CopyAttConfig::prefix(std::string const& parameter) { - this->caf.prefix = parameter; + caf.prefix = parameter; return this; } QPDFJob::CopyAttConfig* QPDFJob::CopyAttConfig::password(std::string const& parameter) { - this->caf.password = parameter; + caf.password = parameter; return this; } QPDFJob::Config* QPDFJob::CopyAttConfig::endCopyAttachmentsFrom() { - if (this->caf.path.empty()) { + if (caf.path.empty()) { usage("copy attachments: no file specified"); } - this->config->o.m->attachments_to_copy.push_back(this->caf); - return this->config; + config->o.m->attachments_to_copy.push_back(caf); + return config; } QPDFJob::AttConfig::AttConfig(Config* c) : @@ -874,21 +874,21 @@ QPDFJob::Config::addAttachment() QPDFJob::AttConfig* QPDFJob::AttConfig::file(std::string const& parameter) { - this->att.path = parameter; + att.path = parameter; return this; } QPDFJob::AttConfig* QPDFJob::AttConfig::key(std::string const& parameter) { - this->att.key = parameter; + att.key = parameter; return this; } QPDFJob::AttConfig* QPDFJob::AttConfig::filename(std::string const& parameter) { - this->att.filename = parameter; + att.filename = parameter; return this; } @@ -898,7 +898,7 @@ QPDFJob::AttConfig::creationdate(std::string const& parameter) if (!QUtil::pdf_time_to_qpdf_time(parameter)) { usage(std::string(parameter) + " is not a valid PDF timestamp"); } - this->att.creationdate = parameter; + att.creationdate = parameter; return this; } @@ -908,7 +908,7 @@ QPDFJob::AttConfig::moddate(std::string const& parameter) if (!QUtil::pdf_time_to_qpdf_time(parameter)) { usage(std::string(parameter) + " is not a valid PDF timestamp"); } - this->att.moddate = parameter; + att.moddate = parameter; return this; } @@ -918,21 +918,21 @@ QPDFJob::AttConfig::mimetype(std::string const& parameter) if (parameter.find('/') == std::string::npos) { usage("mime type should be specified as type/subtype"); } - this->att.mimetype = parameter; + att.mimetype = parameter; return this; } QPDFJob::AttConfig* QPDFJob::AttConfig::description(std::string const& parameter) { - this->att.description = parameter; + att.description = parameter; return this; } QPDFJob::AttConfig* QPDFJob::AttConfig::replace() { - this->att.replace = true; + att.replace = true; return this; } @@ -940,28 +940,28 @@ QPDFJob::Config* QPDFJob::AttConfig::endAddAttachment() { static std::string now = QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time()); - if (this->att.path.empty()) { + if (att.path.empty()) { usage("add attachment: no file specified"); } - std::string last_element = QUtil::path_basename(this->att.path); + std::string last_element = QUtil::path_basename(att.path); if (last_element.empty()) { usage("file for --add-attachment may not be empty"); } - if (this->att.filename.empty()) { - this->att.filename = last_element; + if (att.filename.empty()) { + att.filename = last_element; } - if (this->att.key.empty()) { - this->att.key = last_element; + if (att.key.empty()) { + att.key = last_element; } - if (this->att.creationdate.empty()) { - this->att.creationdate = now; + if (att.creationdate.empty()) { + att.creationdate = now; } - if (this->att.moddate.empty()) { - this->att.moddate = now; + if (att.moddate.empty()) { + att.moddate = now; } - this->config->o.m->attachments_to_add.push_back(this->att); - return this->config; + config->o.m->attachments_to_add.push_back(att); + return config; } QPDFJob::PagesConfig::PagesConfig(Config* c) : @@ -985,21 +985,21 @@ QPDFJob::PagesConfig::endPages() if (n_specs == 0) { usage("--pages: no page specifications given"); } - return this->config; + return config; } QPDFJob::PagesConfig* QPDFJob::PagesConfig::pageSpec( std::string const& filename, std::string const& range, char const* password) { - this->config->o.m->page_specs.emplace_back(filename, password, range); + config->o.m->page_specs.emplace_back(filename, password, range); return this; } QPDFJob::PagesConfig* QPDFJob::PagesConfig::file(std::string const& arg) { - this->config->o.m->page_specs.emplace_back(arg, "", ""); + config->o.m->page_specs.emplace_back(arg, "", ""); return this; } @@ -1063,7 +1063,7 @@ QPDFJob::UOConfig::endUnderlayOverlay() usage(config->o.m->under_overlay->which + " file not specified"); } config->o.m->under_overlay = nullptr; - return this->config; + return config; } QPDFJob::UOConfig* @@ -1192,7 +1192,7 @@ QPDFJob::EncConfig::endEncrypt() config->o.m->encrypt = true; config->o.m->decrypt = false; config->o.m->copy_encryption = false; - return this->config; + return config; } QPDFJob::EncConfig* @@ -1341,5 +1341,5 @@ QPDFJob::PageLabelsConfig::PageLabelsConfig(Config* c) : QPDFJob::Config* QPDFJob::PageLabelsConfig::endSetPageLabels() { - return this->config; + return config; }