Commit 039abac42af05d7aa47d9488c66653ee7dc8a899

Authored by m-holger
1 parent 3fbae967

Refactor linearization checks: change `checkLinearizationInternal` to `void`, si…

…mplify control flow, and update method returns.
include/qpdf/QPDF.hh
@@ -1001,7 +1001,7 @@ class QPDF @@ -1001,7 +1001,7 @@ class QPDF
1001 1001
1002 // methods to support linearization checking -- implemented in QPDF_linearization.cc 1002 // methods to support linearization checking -- implemented in QPDF_linearization.cc
1003 void readLinearizationData(); 1003 void readLinearizationData();
1004 - bool checkLinearizationInternal(); 1004 + void checkLinearizationInternal();
1005 void dumpLinearizationDataInternal(); 1005 void dumpLinearizationDataInternal();
1006 void linearizationWarning(std::string_view); 1006 void linearizationWarning(std::string_view);
1007 QPDFObjectHandle readHintStream(Pipeline&, qpdf_offset_t offset, size_t length); 1007 QPDFObjectHandle readHintStream(Pipeline&, qpdf_offset_t offset, size_t length);
libqpdf/QPDF_linearization.cc
@@ -77,15 +77,15 @@ QPDF::linearizationWarning(std::string_view msg) @@ -77,15 +77,15 @@ QPDF::linearizationWarning(std::string_view msg)
77 bool 77 bool
78 QPDF::checkLinearization() 78 QPDF::checkLinearization()
79 { 79 {
80 - bool result = false;  
81 try { 80 try {
82 readLinearizationData(); 81 readLinearizationData();
83 - result = checkLinearizationInternal(); 82 + checkLinearizationInternal();
  83 + return !m->linearization_warnings;
84 } catch (std::runtime_error& e) { 84 } catch (std::runtime_error& e) {
85 linearizationWarning( 85 linearizationWarning(
86 "error encountered while checking linearization data: " + std::string(e.what())); 86 "error encountered while checking linearization data: " + std::string(e.what()));
  87 + return false;
87 } 88 }
88 - return result;  
89 } 89 }
90 90
91 bool 91 bool
@@ -404,7 +404,7 @@ QPDF::readHGeneric(BitStream h, HGeneric& t) @@ -404,7 +404,7 @@ QPDF::readHGeneric(BitStream h, HGeneric& t)
404 t.group_length = h.getBitsInt(32); // 4 404 t.group_length = h.getBitsInt(32); // 4
405 } 405 }
406 406
407 -bool 407 +void
408 QPDF::checkLinearizationInternal() 408 QPDF::checkLinearizationInternal()
409 { 409 {
410 // All comments referring to the PDF spec refer to the spec for version 1.4. 410 // All comments referring to the PDF spec refer to the spec for version 1.4.
@@ -521,8 +521,6 @@ QPDF::checkLinearizationInternal() @@ -521,8 +521,6 @@ QPDF::checkLinearizationInternal()
521 checkHSharedObject(pages, shared_idx_to_obj); 521 checkHSharedObject(pages, shared_idx_to_obj);
522 checkHPageOffset(pages, shared_idx_to_obj); 522 checkHPageOffset(pages, shared_idx_to_obj);
523 checkHOutlines(); 523 checkHOutlines();
524 -  
525 - return !m->linearization_warnings;  
526 } 524 }
527 525
528 qpdf_offset_t 526 qpdf_offset_t
libqpdf/qpdf/QPDF_private.hh
@@ -519,7 +519,7 @@ class QPDF::Members @@ -519,7 +519,7 @@ class QPDF::Members
519 // Linearization data 519 // Linearization data
520 qpdf_offset_t first_xref_item_offset{0}; // actual value from file 520 qpdf_offset_t first_xref_item_offset{0}; // actual value from file
521 bool uncompressed_after_compressed{false}; 521 bool uncompressed_after_compressed{false};
522 - bool linearization_warnings{false}; 522 + bool linearization_warnings{false}; // set by linearizationWarning, used by checkLinearization
523 523
524 // Linearization parameter dictionary and hint table data: may be read from file or computed 524 // Linearization parameter dictionary and hint table data: may be read from file or computed
525 // prior to writing a linearized file 525 // prior to writing a linearized file