From bedf35d6a55a9092485d56002b50bc9003ce7931 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 2 Jan 2021 12:05:09 -0500 Subject: Bug fix: avoid extraneous pipeline finish calls with multiple contents Avoid calling finish() multiple times on the pipeline passed to pipeContentStreams. This commit also fixes a bug in which qpdf was not exiting with the proper exit status if warnings found while splitting pages; this was exposed by a test case that changed. --- libqpdf/QPDFObjectHandle.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'libqpdf/QPDFObjectHandle.cc') diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index add0b14d..94b81f3d 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -90,13 +89,11 @@ void CoalesceProvider::provideStreamData(int, int, Pipeline* p) { QTC::TC("qpdf", "QPDFObjectHandle coalesce provide stream data"); - Pl_Concatenate concat("concatenate", p); std::string description = "page object " + QUtil::int_to_string(containing_page.getObjectID()) + " " + QUtil::int_to_string(containing_page.getGeneration()); std::string all_description; - old_contents.pipeContentStreams(&concat, description, all_description); - concat.manualFinish(); + old_contents.pipeContentStreams(p, description, all_description); } void @@ -1630,14 +1627,15 @@ QPDFObjectHandle::pipeContentStreams( arrayOrStreamToStreamArray( description, all_description); bool need_newline = false; + Pl_Buffer buf("concatenated content stream buffer"); for (std::vector::iterator iter = streams.begin(); iter != streams.end(); ++iter) { if (need_newline) { - p->write(QUtil::unsigned_char_pointer("\n"), 1); + buf.write(QUtil::unsigned_char_pointer("\n"), 1); } - LastChar lc(p); + LastChar lc(&buf); QPDFObjectHandle stream = *iter; std::string og = QUtil::int_to_string(stream.getObjectID()) + " " + @@ -1655,6 +1653,9 @@ QPDFObjectHandle::pipeContentStreams( QTC::TC("qpdf", "QPDFObjectHandle need_newline", need_newline ? 0 : 1); } + std::unique_ptr b(buf.getBuffer()); + p->write(b->getBuffer(), b->getSize()); + p->finish(); } void -- cgit v1.2.3-54-g00ecf