summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-03-06 18:43:27 +0100
committerm-holger <m-holger@kubitscheck.org>2023-03-08 10:50:49 +0100
commit71bba5d40dcbeac5bd2741ca155c111d9a3ee47b (patch)
tree32ad9f72796bec2452a422bb318b96198c3aef66
parentb27be3ed27890ae8226560817f14c117927cee55 (diff)
downloadqpdf-71bba5d40dcbeac5bd2741ca155c111d9a3ee47b.tar.zst
Code tidy QdfFixer::writeBinary
-rw-r--r--qpdf/fix-qdf.cc12
1 files 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<char>(QIntC::to_uchar(val & 0xff));
- val >>= 8;
+ std::string data(bytes, '\0');
+ for (auto i = bytes; i > 0; --i) {
+ data[i - 1] = static_cast<char>(val & 0xff); // i.e. val % 256
+ val >>= 8; // i.e. val = val / 256
}
std::cout << data;
}