aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-08-29 18:27:59 +0200
committerJay Berkenbilt <ejb@ql.org>2017-08-29 18:28:32 +0200
commit1868a10f8b06631362618bfc85ca8646da4b4b71 (patch)
treec3029002f777a9904bfa3dff559daea989c79025 /libqpdf
parent742190bd98c0981a07cb39a8eae1e99d909ad5ae (diff)
downloadqpdf-1868a10f8b06631362618bfc85ca8646da4b4b71.tar.zst
Replace all atoi calls with QUtil::string_to_int
The latter catches underflow/overflow.
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDF.cc16
-rw-r--r--libqpdf/QPDFWriter.cc10
2 files changed, 14 insertions, 12 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 86e798ee..bea83c98 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -440,8 +440,8 @@ QPDF::reconstruct_xref(QPDFExc& e)
(t3 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "obj")))
{
in_obj = true;
- int obj = atoi(t1.getValue().c_str());
- int gen = atoi(t2.getValue().c_str());
+ int obj = QUtil::string_to_int(t1.getValue().c_str());
+ int gen = QUtil::string_to_int(t2.getValue().c_str());
insertXrefEntry(obj, 1, token_start, gen, true);
}
}
@@ -610,8 +610,8 @@ QPDF::parse_xrefFirst(std::string const& line,
++p;
}
bytes = p - start;
- obj = atoi(obj_str.c_str());
- num = atoi(num_str.c_str());
+ obj = QUtil::string_to_int(obj_str.c_str());
+ num = QUtil::string_to_int(num_str.c_str());
return true;
}
@@ -706,7 +706,7 @@ QPDF::parse_xrefEntry(std::string const& line,
}
f1 = QUtil::string_to_ll(f1_str.c_str());
- f2 = atoi(f2_str.c_str());
+ f2 = QUtil::string_to_int(f2_str.c_str());
return true;
}
@@ -1570,8 +1570,8 @@ QPDF::readObjectAtOffset(bool try_recovery,
this->m->last_object_description, offset,
"expected n n obj");
}
- objid = atoi(tobjid.getValue().c_str());
- generation = atoi(tgen.getValue().c_str());
+ objid = QUtil::string_to_int(tobjid.getValue().c_str());
+ generation = QUtil::string_to_int(tgen.getValue().c_str());
if (objid == 0)
{
@@ -1855,7 +1855,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
"expected integer in object stream header");
}
- int num = atoi(tnum.getValue().c_str());
+ int num = QUtil::string_to_int(tnum.getValue().c_str());
int offset = QUtil::string_to_ll(toffset.getValue().c_str());
offsets[num] = offset + first;
}
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index ee2ab32e..1ce4bfb6 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -661,8 +661,10 @@ QPDFWriter::disableIncompatibleEncryption(int major, int minor,
}
else
{
- int V = atoi(this->m->encryption_dictionary["/V"].c_str());
- int R = atoi(this->m->encryption_dictionary["/R"].c_str());
+ int V = QUtil::string_to_int(
+ this->m->encryption_dictionary["/V"].c_str());
+ int R = QUtil::string_to_int(
+ this->m->encryption_dictionary["/R"].c_str());
if (compareVersions(major, minor, 1, 4) < 0)
{
if ((V > 1) || (R > 2))
@@ -705,12 +707,12 @@ void
QPDFWriter::parseVersion(std::string const& version,
int& major, int& minor) const
{
- major = atoi(version.c_str());
+ major = QUtil::string_to_int(version.c_str());
minor = 0;
size_t p = version.find('.');
if ((p != std::string::npos) && (version.length() > p))
{
- minor = atoi(version.substr(p + 1).c_str());
+ minor = QUtil::string_to_int(version.substr(p + 1).c_str());
}
std::string tmp = QUtil::int_to_string(major) + "." +
QUtil::int_to_string(minor);