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-54-g00ecf