2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-24 07:38:28 +00:00

Code tidy QdfFixer::writeBinary

This commit is contained in:
m-holger 2023-03-06 17:43:27 +00:00
parent b27be3ed27
commit 71bba5d40d

View File

@ -363,14 +363,10 @@ QdfFixer::writeBinary(unsigned long long val, size_t bytes)
throw std::logic_error( throw std::logic_error(
"fix-qdf::writeBinary called with too many bytes"); "fix-qdf::writeBinary called with too many bytes");
} }
std::string data; std::string data(bytes, '\0');
data.reserve(bytes); for (auto i = bytes; i > 0; --i) {
for (size_t i = 0; i < bytes; ++i) { data[i - 1] = static_cast<char>(val & 0xff); // i.e. val % 256
data.append(1, '\0'); val >>= 8; // i.e. val = val / 256
}
for (size_t i = 0; i < bytes; ++i) {
data.at(bytes - i - 1) = static_cast<char>(QIntC::to_uchar(val & 0xff));
val >>= 8;
} }
std::cout << data; std::cout << data;
} }