2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-03 15:17:29 +00:00

Code tidy: use QPDF::toS and QPDF::toI where possible

This commit is contained in:
m-holger 2022-07-13 14:24:19 +01:00 committed by Jay Berkenbilt
parent 5ccab4be03
commit cb0a6be983
4 changed files with 13 additions and 17 deletions

View File

@ -1911,7 +1911,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
int num = QUtil::string_to_int(tnum.getValue().c_str()); int num = QUtil::string_to_int(tnum.getValue().c_str());
long long offset = QUtil::string_to_int(toffset.getValue().c_str()); long long offset = QUtil::string_to_int(toffset.getValue().c_str());
offsets[num] = QIntC::to_int(offset + first); offsets[num] = toI(offset + first);
} }
// To avoid having to read the object stream multiple times, store // To avoid having to read the object stream multiple times, store

View File

@ -422,11 +422,9 @@ QPDF::compute_encryption_key_from_password(
md5.encodeDataIncrementally(bytes, 4); md5.encodeDataIncrementally(bytes, 4);
} }
MD5::Digest digest; MD5::Digest digest;
int key_len = int key_len = std::min(toI(sizeof(digest)), data.getLengthBytes());
std::min(QIntC::to_int(sizeof(digest)), data.getLengthBytes());
iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0), key_len); iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0), key_len);
return std::string( return std::string(reinterpret_cast<char*>(digest), toS(key_len));
reinterpret_cast<char*>(digest), QIntC::to_size(key_len));
} }
static void static void

View File

@ -128,8 +128,7 @@ QPDF::isLinearized()
(t2.getType() == QPDFTokenizer::tt_integer) && (t2.getType() == QPDFTokenizer::tt_integer) &&
(t3 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "obj")) && (t3 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "obj")) &&
(t4.getType() == QPDFTokenizer::tt_dict_open)) { (t4.getType() == QPDFTokenizer::tt_dict_open)) {
lindict_obj = lindict_obj = toI(QUtil::string_to_ll(t1.getValue().c_str()));
QIntC::to_int(QUtil::string_to_ll(t1.getValue().c_str()));
} }
} }
@ -143,8 +142,7 @@ QPDF::isLinearized()
} }
QPDFObjectHandle linkey = candidate.getKey("/Linearized"); QPDFObjectHandle linkey = candidate.getKey("/Linearized");
if (!(linkey.isNumber() && if (!(linkey.isNumber() && (toI(floor(linkey.getNumericValue())) == 1))) {
(QIntC::to_int(floor(linkey.getNumericValue())) == 1))) {
return false; return false;
} }
@ -1797,7 +1795,7 @@ QPDF::calculateHSharedObject(
soe.push_back(HSharedObjectEntry()); soe.push_back(HSharedObjectEntry());
soe.at(i).delta_group_length = length; soe.at(i).delta_group_length = length;
} }
if (soe.size() != QIntC::to_size(cso.nshared_total)) { if (soe.size() != toS(cso.nshared_total)) {
stopOnError("soe has wrong size after initialization"); stopOnError("soe has wrong size after initialization");
} }

View File

@ -238,7 +238,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
QTC::TC("qpdf", "QPDF insert indirect page"); QTC::TC("qpdf", "QPDF insert indirect page");
} }
if ((pos < 0) || (QIntC::to_size(pos) > this->m->all_pages.size())) { if ((pos < 0) || (toS(pos) > m->all_pages.size())) {
throw std::runtime_error( throw std::runtime_error(
"QPDF::insertPage called with pos out of range"); "QPDF::insertPage called with pos out of range");
} }
@ -247,7 +247,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
"qpdf", "qpdf",
"QPDF insert page", "QPDF insert page",
(pos == 0) ? 0 : // insert at beginning (pos == 0) ? 0 : // insert at beginning
(pos == QIntC::to_int(this->m->all_pages.size())) ? 1 (pos == toI(m->all_pages.size())) ? 1
: // at end : // at end
2); // insert in middle 2); // insert in middle
@ -279,7 +279,7 @@ QPDF::removePage(QPDFObjectHandle page)
"qpdf", "qpdf",
"QPDF remove page", "QPDF remove page",
(pos == 0) ? 0 : // remove at beginning (pos == 0) ? 0 : // remove at beginning
(pos == QIntC::to_int(this->m->all_pages.size() - 1)) ? 1 (pos == toI(m->all_pages.size() - 1)) ? 1
: // end : // end
2); // remove in middle 2); // remove in middle