From 71bba5d40dcbeac5bd2741ca155c111d9a3ee47b Mon Sep 17 00:00:00 2001 From: m-holger Date: Mon, 6 Mar 2023 17:43:27 +0000 Subject: Code tidy QdfFixer::writeBinary --- qpdf/fix-qdf.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/qpdf/fix-qdf.cc b/qpdf/fix-qdf.cc index 8ab3e278..9992d26c 100644 --- a/qpdf/fix-qdf.cc +++ b/qpdf/fix-qdf.cc @@ -363,14 +363,10 @@ QdfFixer::writeBinary(unsigned long long val, size_t bytes) throw std::logic_error( "fix-qdf::writeBinary called with too many bytes"); } - std::string data; - data.reserve(bytes); - for (size_t i = 0; i < bytes; ++i) { - data.append(1, '\0'); - } - for (size_t i = 0; i < bytes; ++i) { - data.at(bytes - i - 1) = static_cast(QIntC::to_uchar(val & 0xff)); - val >>= 8; + std::string data(bytes, '\0'); + for (auto i = bytes; i > 0; --i) { + data[i - 1] = static_cast(val & 0xff); // i.e. val % 256 + val >>= 8; // i.e. val = val / 256 } std::cout << data; } -- cgit v1.2.3-70-g09d2 From fc828c2a5093e6f4eda81c817b4db4a0c8bb0984 Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 7 Mar 2023 19:02:49 +0000 Subject: Tidy QdfFixer::checkObjId --- qpdf/fix-qdf.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/qpdf/fix-qdf.cc b/qpdf/fix-qdf.cc index 9992d26c..83632f4d 100644 --- a/qpdf/fix-qdf.cc +++ b/qpdf/fix-qdf.cc @@ -297,14 +297,12 @@ QdfFixer::processLines(std::list& lines) void QdfFixer::checkObjId(std::string const& cur_obj_str) { - int cur_obj = QUtil::string_to_int(cur_obj_str.c_str()); - if (cur_obj != last_obj + 1) { + if (std::stoi(cur_obj_str) != ++last_obj) { fatal( filename + ":" + std::to_string(lineno) + ": expected object " + - std::to_string(last_obj + 1)); + std::to_string(last_obj)); } - last_obj = cur_obj; - xref.push_back(QPDFXRefEntry(1, QIntC::to_offset(last_offset), 0)); + xref.push_back(QPDFXRefEntry(1, last_offset, 0)); } void -- cgit v1.2.3-70-g09d2 From 82efe52b7dd664f4ae38f8932a9906e5232030cf Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 7 Mar 2023 19:05:26 +0000 Subject: Tidy QdfFixer::adjustOstreamXref --- qpdf/fix-qdf.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/qpdf/fix-qdf.cc b/qpdf/fix-qdf.cc index 83632f4d..4445fbd1 100644 --- a/qpdf/fix-qdf.cc +++ b/qpdf/fix-qdf.cc @@ -308,8 +308,7 @@ QdfFixer::checkObjId(std::string const& cur_obj_str) void QdfFixer::adjustOstreamXref() { - xref.pop_back(); - xref.push_back(QPDFXRefEntry(2, ostream_id, QIntC::to_int(ostream_idx++))); + xref.back() = QPDFXRefEntry(2, ostream_id, QIntC::to_int(ostream_idx++)); } void -- cgit v1.2.3-70-g09d2