aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_linearization.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-10-05 22:37:27 +0200
committerJay Berkenbilt <ejb@ql.org>2013-10-10 02:57:14 +0200
commite19eb579b221ade503d7d1ff0a6511d289863785 (patch)
tree8e0d330ff9d4132eadacc399affb7bcb1a1b5933 /libqpdf/QPDF_linearization.cc
parent0bfe9024893ebb1f62108fe6c24410e6ba589c3e (diff)
downloadqpdf-e19eb579b221ade503d7d1ff0a6511d289863785.tar.zst
Replace some assertions with std::logic_error
Ideally, the library should never call assert outside of test code, but it does in several places. For some cases where the assertion might conceivably fail because of a problem with the input data, replace assertions with exceptions so that they can be trapped by the calling application. This commit surely misses some cases and replaced some cases unnecessarily, but it should still be an improvement.
Diffstat (limited to 'libqpdf/QPDF_linearization.cc')
-rw-r--r--libqpdf/QPDF_linearization.cc33
1 files changed, 26 insertions, 7 deletions
diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc
index 7d2560d3..4b28e480 100644
--- a/libqpdf/QPDF_linearization.cc
+++ b/libqpdf/QPDF_linearization.cc
@@ -606,15 +606,21 @@ QPDF::checkLinearizationInternal()
// agree with pdlin. As of this writing, the test suite doesn't
// contain any files with threads.
- assert(! this->part6.empty());
+ if (this->part6.empty())
+ {
+ throw std::logic_error("linearization part 6 unexpectedly empty");
+ }
qpdf_offset_t min_E = -1;
qpdf_offset_t max_E = -1;
for (std::vector<QPDFObjectHandle>::iterator iter = this->part6.begin();
iter != this->part6.end(); ++iter)
{
QPDFObjGen og((*iter).getObjGen());
- // All objects have to have been dereferenced to be classified.
- assert(this->obj_cache.count(og) > 0);
+ if (this->obj_cache.count(og) == 0)
+ {
+ // All objects have to have been dereferenced to be classified.
+ throw std::logic_error("linearization part6 object not in cache");
+ }
ObjCache const& oc = this->obj_cache[og];
min_E = std::max(min_E, oc.end_before_space);
max_E = std::max(max_E, oc.end_after_space);
@@ -832,14 +838,23 @@ QPDF::checkHPageOffset(std::list<std::string>& errors,
for (int i = 0; i < he.nshared_objects; ++i)
{
int idx = he.shared_identifiers[i];
- assert(shared_idx_to_obj.count(idx) > 0);
+ if (shared_idx_to_obj.count(idx) == 0)
+ {
+ throw std::logic_error(
+ "unable to get object for item in"
+ " shared objects hint table");
+ }
hint_shared.insert(shared_idx_to_obj[idx]);
}
for (int i = 0; i < ce.nshared_objects; ++i)
{
int idx = ce.shared_identifiers[i];
- assert(idx < this->c_shared_object_data.nshared_total);
+ if (idx >= this->c_shared_object_data.nshared_total)
+ {
+ throw std::logic_error(
+ "index out of bounds for shared object hint table");
+ }
int obj = this->c_shared_object_data.entries[idx].object;
computed_shared.insert(obj);
}
@@ -1754,8 +1769,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
shared.push_back(CHSharedObjectEntry(obj));
}
}
- assert(static_cast<size_t>(this->c_shared_object_data.nshared_total) ==
- this->c_shared_object_data.entries.size());
+ if (static_cast<size_t>(this->c_shared_object_data.nshared_total) !=
+ this->c_shared_object_data.entries.size())
+ {
+ throw std::logic_error(
+ "shared object hint table has wrong number of entries");
+ }
// Now compute the list of shared objects for each page after the
// first page.