From e5edfc786f0dab9435379a7420c17695128466b2 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jan 2022 18:27:14 -0500 Subject: QPDFJob: convert infilename to shared pointer --- libqpdf/QPDFJob.cc | 17 ++++++++--------- libqpdf/QPDFJob_argv.cc | 7 ++++--- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 5a832c21..00546652 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -414,7 +414,6 @@ QPDFJob::QPDFJob() : replace_input(false), check_is_encrypted(false), check_requires_password(false), - infilename(0), outfilename(0), m(new Members()) { @@ -451,7 +450,7 @@ QPDFJob::run() std::shared_ptr pdf_ph; try { - pdf_ph = processFile(o.infilename, o.password.get()); + pdf_ph = processFile(o.infilename.get(), o.password.get()); } catch (QPDFExc& e) { @@ -2554,7 +2553,7 @@ QPDFJob::handlePageSpecs( QPDFJob::PageSpec& page_spec = *iter; if (page_spec.filename == ".") { - page_spec.filename = o.infilename; + page_spec.filename = o.infilename.get(); } } @@ -2582,7 +2581,7 @@ QPDFJob::handlePageSpecs( // Create a QPDF object for each file that we may take pages from. std::map page_spec_qpdfs; std::map page_spec_cfis; - page_spec_qpdfs[o.infilename] = &pdf; + page_spec_qpdfs[o.infilename.get()] = &pdf; std::vector parsed_specs; std::map > copied_pages; for (std::vector::iterator iter = o.page_specs.begin(); @@ -3364,7 +3363,7 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) QUtil::uint_to_string(last, QIntC::to_int(pageno_len)); } std::string outfile = before + page_range + after; - if (QUtil::same_file(o.infilename, outfile.c_str())) + if (QUtil::same_file(o.infilename.get(), outfile.c_str())) { throw std::runtime_error( "split pages would overwrite input file with " + outfile); @@ -3392,7 +3391,7 @@ QPDFJob::writeOutfile(QPDF& pdf) // Append but don't prepend to the path to generate a // temporary name. This saves us from having to split the path // by directory and non-directory. - temp_out = std::string(o.infilename) + ".~qpdf-temp#"; + temp_out = std::string(o.infilename.get()) + ".~qpdf-temp#"; // o.outfilename will be restored to 0 before temp_out // goes out of scope. o.outfilename = temp_out.c_str(); @@ -3421,14 +3420,14 @@ QPDFJob::writeOutfile(QPDF& pdf) { // We must close the input before we can rename files pdf.closeInputSource(); - std::string backup = std::string(o.infilename) + ".~qpdf-orig"; + std::string backup = std::string(o.infilename.get()) + ".~qpdf-orig"; bool warnings = pdf.anyWarnings(); if (! warnings) { backup.append(1, '#'); } - QUtil::rename_file(o.infilename, backup.c_str()); - QUtil::rename_file(temp_out.c_str(), o.infilename); + QUtil::rename_file(o.infilename.get(), backup.c_str()); + QUtil::rename_file(temp_out.c_str(), o.infilename.get()); if (warnings) { *(this->m->cerr) diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc index 17f163ef..0fb7d408 100644 --- a/libqpdf/QPDFJob_argv.cc +++ b/libqpdf/QPDFJob_argv.cc @@ -68,7 +68,7 @@ ArgParser::argPositional(char* arg) { if (o.infilename == 0) { - o.infilename = arg; + o.infilename = QUtil::make_shared_cstr(arg); } else if (o.outfilename == 0) { @@ -211,7 +211,7 @@ ArgParser::argPasswordFile(char* parameter) void ArgParser::argEmpty() { - o.infilename = ""; + o.infilename = QUtil::make_shared_cstr(""); } void @@ -1513,7 +1513,8 @@ ArgParser::doFinalChecks() } } - if ((! o.split_pages) && QUtil::same_file(o.infilename, o.outfilename)) + if ((! o.split_pages) && + QUtil::same_file(o.infilename.get(), o.outfilename)) { QTC::TC("qpdf", "qpdf same file error"); usage("input file and output file are the same;" -- cgit v1.2.3-70-g09d2