From 85a3f95a89ca392a3726f8d964024dfd10177e09 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jun 2019 13:18:26 -0400 Subject: qpdf: exit 3 for linearization warnings without errors (fixes #50) --- libqpdf/QPDF_linearization.cc | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 5eb6277e..cb607fed 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -65,17 +65,25 @@ load_vector_vector(BitStream& bit_stream, bool QPDF::checkLinearization() { - bool result = false; + bool errors = false; + bool warnings = false; + checkLinearization(errors, warnings); + return (! (errors || warnings)); +} + +void +QPDF::checkLinearization(bool& errors, bool& warnings) +{ try { readLinearizationData(); - result = checkLinearizationInternal(); + checkLinearizationInternal(errors, warnings); } catch (QPDFExc& e) { *this->m->out_stream << e.what() << std::endl; + errors = true; } - return result; } bool @@ -499,8 +507,8 @@ QPDF::readHGeneric(BitStream h, HGeneric& t) t.group_length = h.getBitsInt(32); // 4 } -bool -QPDF::checkLinearizationInternal() +void +QPDF::checkLinearizationInternal(bool& any_errors, bool& any_warnings) { // All comments referring to the PDF spec refer to the spec for // version 1.4. @@ -648,11 +656,11 @@ QPDF::checkLinearizationInternal() // Report errors - bool result = true; + any_errors = (! errors.empty()); + any_warnings = (! warnings.empty()); - if (! errors.empty()) + if (any_errors) { - result = false; for (std::list::iterator iter = errors.begin(); iter != errors.end(); ++iter) { @@ -660,17 +668,14 @@ QPDF::checkLinearizationInternal() } } - if (! warnings.empty()) + if (any_warnings) { - result = false; for (std::list::iterator iter = warnings.begin(); iter != warnings.end(); ++iter) { *this->m->out_stream << "WARNING: " << (*iter) << std::endl; } } - - return result; } qpdf_offset_t @@ -1084,7 +1089,9 @@ QPDF::showLinearizationData() try { readLinearizationData(); - checkLinearizationInternal(); + bool errors = false; + bool warnings = false; + checkLinearizationInternal(errors, warnings); dumpLinearizationDataInternal(); } catch (QPDFExc& e) -- cgit v1.2.3-70-g09d2