Commit aefb8ff9efe06b6a596fac8140daea605ff149ff
Committed by
Jay Berkenbilt
1 parent
8363657c
Refactor QPDFWriter::writePad
Showing
2 changed files
with
11 additions
and
20 deletions
include/qpdf/QPDFWriter.hh
| ... | ... | @@ -557,7 +557,7 @@ class QPDFWriter |
| 557 | 557 | void writeBuffer(std::shared_ptr<Buffer>&); |
| 558 | 558 | void writeStringQDF(std::string const& str); |
| 559 | 559 | void writeStringNoQDF(std::string const& str); |
| 560 | - void writePad(int nspaces); | |
| 560 | + void writePad(size_t nspaces); | |
| 561 | 561 | void assignCompressedObjectNumbers(QPDFObjGen const& og); |
| 562 | 562 | void enqueueObject(QPDFObjectHandle object); |
| 563 | 563 | void writeObjectStreamOffsets( |
| ... | ... | @@ -676,7 +676,7 @@ class QPDFWriter |
| 676 | 676 | qpdf_offset_t hint_length, |
| 677 | 677 | bool skip_compression, |
| 678 | 678 | int linearization_pass); |
| 679 | - int calculateXrefStreamPadding(qpdf_offset_t xref_bytes); | |
| 679 | + size_t calculateXrefStreamPadding(qpdf_offset_t xref_bytes); | |
| 680 | 680 | |
| 681 | 681 | // When filtering subsections, push additional pipelines to the |
| 682 | 682 | // stack. When ready to switch, activate the pipeline stack. When | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -1010,11 +1010,9 @@ QPDFWriter::writeStringNoQDF(std::string const& str) |
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | void |
| 1013 | -QPDFWriter::writePad(int nspaces) | |
| 1013 | +QPDFWriter::writePad(size_t nspaces) | |
| 1014 | 1014 | { |
| 1015 | - for (int i = 0; i < nspaces; ++i) { | |
| 1016 | - writeString(" "); | |
| 1017 | - } | |
| 1015 | + writeString(std::string(nspaces, ' ')); | |
| 1018 | 1016 | } |
| 1019 | 1017 | |
| 1020 | 1018 | Pipeline* |
| ... | ... | @@ -1321,13 +1319,8 @@ QPDFWriter::writeTrailer( |
| 1321 | 1319 | writeString(" /Prev "); |
| 1322 | 1320 | qpdf_offset_t pos = this->m->pipeline->getCount(); |
| 1323 | 1321 | writeString(std::to_string(prev)); |
| 1324 | - int nspaces = | |
| 1325 | - QIntC::to_int(pos - this->m->pipeline->getCount() + 21); | |
| 1326 | - if (nspaces < 0) { | |
| 1327 | - throw std::logic_error( | |
| 1328 | - "QPDFWriter: no padding required in trailer"); | |
| 1329 | - } | |
| 1330 | - writePad(nspaces); | |
| 1322 | + writePad(QIntC::to_size( | |
| 1323 | + pos - this->m->pipeline->getCount() + 21)); | |
| 1331 | 1324 | } |
| 1332 | 1325 | } else { |
| 1333 | 1326 | unparseChild(trailer.getKey(key), 1, 0); |
| ... | ... | @@ -2783,7 +2776,7 @@ QPDFWriter::writeXRefStream( |
| 2783 | 2776 | return space_before_zero; |
| 2784 | 2777 | } |
| 2785 | 2778 | |
| 2786 | -int | |
| 2779 | +size_t | |
| 2787 | 2780 | QPDFWriter::calculateXrefStreamPadding(qpdf_offset_t xref_bytes) |
| 2788 | 2781 | { |
| 2789 | 2782 | // This routine is called right after a linearization first pass |
| ... | ... | @@ -2794,7 +2787,7 @@ QPDFWriter::calculateXrefStreamPadding(qpdf_offset_t xref_bytes) |
| 2794 | 2787 | // input by 6 bytes plus 5 bytes per 16K, and then we'll add 10 |
| 2795 | 2788 | // extra bytes for number length increases. |
| 2796 | 2789 | |
| 2797 | - return QIntC::to_int(16 + (5 * ((xref_bytes + 16383) / 16384))); | |
| 2790 | + return QIntC::to_size(16 + (5 * ((xref_bytes + 16383) / 16384))); | |
| 2798 | 2791 | } |
| 2799 | 2792 | |
| 2800 | 2793 | void |
| ... | ... | @@ -3029,9 +3022,7 @@ QPDFWriter::writeLinearized() |
| 3029 | 3022 | writeString(" >>"); |
| 3030 | 3023 | closeObject(lindict_id); |
| 3031 | 3024 | static int const pad = 200; |
| 3032 | - int spaces = QIntC::to_int(pos - this->m->pipeline->getCount() + pad); | |
| 3033 | - qpdf_assert_debug(spaces >= 0); | |
| 3034 | - writePad(spaces); | |
| 3025 | + writePad(QIntC::to_size(pos - this->m->pipeline->getCount() + pad)); | |
| 3035 | 3026 | writeString("\n"); |
| 3036 | 3027 | |
| 3037 | 3028 | // If the user supplied any additional header text, write it |
| ... | ... | @@ -3082,7 +3073,7 @@ QPDFWriter::writeLinearized() |
| 3082 | 3073 | } else { |
| 3083 | 3074 | // Pad so that the next object starts at the same |
| 3084 | 3075 | // place as in pass 1. |
| 3085 | - writePad(QIntC::to_int(first_xref_end - endpos)); | |
| 3076 | + writePad(QIntC::to_size(first_xref_end - endpos)); | |
| 3086 | 3077 | |
| 3087 | 3078 | if (this->m->pipeline->getCount() != first_xref_end) { |
| 3088 | 3079 | throw std::logic_error( |
| ... | ... | @@ -3164,7 +3155,7 @@ QPDFWriter::writeLinearized() |
| 3164 | 3155 | second_xref_end = this->m->pipeline->getCount(); |
| 3165 | 3156 | } else { |
| 3166 | 3157 | // Make the file size the same. |
| 3167 | - writePad(QIntC::to_int( | |
| 3158 | + writePad(QIntC::to_size( | |
| 3168 | 3159 | second_xref_end + hint_length - 1 - |
| 3169 | 3160 | this->m->pipeline->getCount())); |
| 3170 | 3161 | writeString("\n"); | ... | ... |