2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +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());
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

View File

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

View File

@ -128,8 +128,7 @@ QPDF::isLinearized()
(t2.getType() == QPDFTokenizer::tt_integer) &&
(t3 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "obj")) &&
(t4.getType() == QPDFTokenizer::tt_dict_open)) {
lindict_obj =
QIntC::to_int(QUtil::string_to_ll(t1.getValue().c_str()));
lindict_obj = toI(QUtil::string_to_ll(t1.getValue().c_str()));
}
}
@ -143,8 +142,7 @@ QPDF::isLinearized()
}
QPDFObjectHandle linkey = candidate.getKey("/Linearized");
if (!(linkey.isNumber() &&
(QIntC::to_int(floor(linkey.getNumericValue())) == 1))) {
if (!(linkey.isNumber() && (toI(floor(linkey.getNumericValue())) == 1))) {
return false;
}
@ -1797,7 +1795,7 @@ QPDF::calculateHSharedObject(
soe.push_back(HSharedObjectEntry());
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");
}

View File

@ -238,7 +238,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
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(
"QPDF::insertPage called with pos out of range");
}
@ -247,9 +247,9 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
"qpdf",
"QPDF insert page",
(pos == 0) ? 0 : // insert at beginning
(pos == QIntC::to_int(this->m->all_pages.size())) ? 1
: // at end
2); // insert in middle
(pos == toI(m->all_pages.size())) ? 1
: // at end
2); // insert in middle
auto og = newpage.getObjGen();
if (this->m->pageobj_to_pages_pos.count(og)) {
@ -279,9 +279,9 @@ QPDF::removePage(QPDFObjectHandle page)
"qpdf",
"QPDF remove page",
(pos == 0) ? 0 : // remove at beginning
(pos == QIntC::to_int(this->m->all_pages.size() - 1)) ? 1
: // end
2); // remove in middle
(pos == toI(m->all_pages.size() - 1)) ? 1
: // end
2); // remove in middle
QPDFObjectHandle pages = getRoot().getKey("/Pages");
QPDFObjectHandle kids = pages.getKey("/Kids");