From 21d6e3231f627470ee58b06df018f31de9eb3201 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 3 May 2022 18:09:49 -0400 Subject: [PATCH] Make use of the new Pipeline methods in some places --- examples/pdf-create.cc | 4 +--- libqpdf/Pl_DCT.cc | 4 +--- libqpdf/QPDF.cc | 2 +- libqpdf/QPDFFormFieldObjectHelper.cc | 2 +- libqpdf/QPDFObjectHandle.cc | 4 ++-- libqpdf/QPDFPageObjectHelper.cc | 2 +- libqpdf/QPDFWriter.cc | 4 ++-- libqpdf/QPDF_encryption.cc | 12 ++++++------ qpdf/test_driver.cc | 21 ++++++++------------- 9 files changed, 23 insertions(+), 32 deletions(-) diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc index 6ba76f63..493b0d3d 100644 --- a/examples/pdf-create.cc +++ b/examples/pdf-create.cc @@ -118,9 +118,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) for (size_t i = 0; i < n_stripes; ++i) { for (size_t j = 0; j < width * stripe_height; ++j) { - p->write( - QUtil::unsigned_char_pointer(stripes[i].c_str()), - stripes[i].length()); + p->writeString(stripes[i]); } } p->finish(); diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc index a05dd48b..9c33b6e1 100644 --- a/libqpdf/Pl_DCT.cc +++ b/libqpdf/Pl_DCT.cc @@ -348,9 +348,7 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b) (void)jpeg_start_decompress(cinfo); while (cinfo->output_scanline < cinfo->output_height) { (void)jpeg_read_scanlines(cinfo, buffer, 1); - this->getNext()->write( - reinterpret_cast(buffer[0]), - width * sizeof(buffer[0][0])); + this->getNext()->write(buffer[0], width * sizeof(buffer[0][0])); } (void)jpeg_finish_decompress(cinfo); this->getNext()->finish(); diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 815894d3..aa99942c 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2739,7 +2739,7 @@ QPDF::pipeStreamData( "unexpected EOF reading stream data"); } length -= len; - pipeline->write(QUtil::unsigned_char_pointer(buf), len); + pipeline->write(buf, len); } pipeline->finish(); success = true; diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index bccea123..a89b8b82 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -863,7 +863,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance( TfFinder tff; Pl_QPDFTokenizer tok("tf", &tff); - tok.write(QUtil::unsigned_char_pointer(DA.c_str()), DA.length()); + tok.writeString(DA); tok.finish(); double tf = tff.getTf(); DA = tff.getDA(); diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index e1c9488a..05a0f30d 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -127,7 +127,7 @@ QPDFObjectHandle::TokenFilter::write(char const* data, size_t len) return; } if (len) { - this->pipeline->write(QUtil::unsigned_char_pointer(data), len); + this->pipeline->write(data, len); } } @@ -1857,7 +1857,7 @@ QPDFObjectHandle::pipeContentStreams( Pl_Buffer buf("concatenated content stream buffer"); for (auto stream: streams) { if (need_newline) { - buf.write(QUtil::unsigned_char_pointer("\n"), 1); + buf.writeCStr("\n"); } LastChar lc(&buf); std::string og = QUtil::int_to_string(stream.getObjectID()) + " " + diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index 59b9b45f..a8880ec0 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -190,7 +190,7 @@ InlineImageTracker::handleToken(QPDFTokenizer::Token const& token) QTC::TC( "qpdf", "QPDFPageObjectHelper externalize inline image"); Pl_Buffer b("image_data"); - b.write(QUtil::unsigned_char_pointer(image_data), len); + b.writeString(image_data); b.finish(); QPDFObjectHandle dict = convertIIDict(QPDFObjectHandle::parse(dict_str)); diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 4b2e785a..35041249 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -961,7 +961,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) void QPDFWriter::writeString(std::string const& str) { - this->m->pipeline->write(QUtil::unsigned_char_pointer(str), str.length()); + this->m->pipeline->writeString(str); } void @@ -1736,7 +1736,7 @@ QPDFWriter::unparseObject( true, QUtil::unsigned_char_pointer(this->m->cur_data_key), this->m->cur_data_key.length()); - pl.write(QUtil::unsigned_char_pointer(val), val.length()); + pl.writeString(val); pl.finish(); auto buf = bufpl.getBufferSharedPointer(); val = QPDF_String(std::string( diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 5fb1e808..5a7968ca 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -235,7 +235,7 @@ process_with_aes( } aes.disablePadding(); for (unsigned int i = 0; i < repetitions; ++i) { - aes.write(QUtil::unsigned_char_pointer(data), data.length()); + aes.writeString(data); } aes.finish(); auto bufp = buffer.getBufferSharedPointer(); @@ -255,9 +255,9 @@ hash_V5( QPDF::EncryptionData const& data) { Pl_SHA2 hash(256); - hash.write(QUtil::unsigned_char_pointer(password), password.length()); - hash.write(QUtil::unsigned_char_pointer(salt), salt.length()); - hash.write(QUtil::unsigned_char_pointer(udata), udata.length()); + hash.writeString(password); + hash.writeString(salt); + hash.writeString(udata); hash.finish(); std::string K = hash.getRawDigest(); @@ -311,7 +311,7 @@ hash_V5( E_mod_3 %= 3; int next_hash = ((E_mod_3 == 0) ? 256 : (E_mod_3 == 1) ? 384 : 512); Pl_SHA2 sha2(next_hash); - sha2.write(QUtil::unsigned_char_pointer(E), E.length()); + sha2.writeString(E); sha2.finish(); K = sha2.getRawDigest(); @@ -1151,7 +1151,7 @@ QPDF::decryptString(std::string& str, int objid, int generation) false, QUtil::unsigned_char_pointer(key), key.length()); - pl.write(QUtil::unsigned_char_pointer(str), str.length()); + pl.writeString(str); pl.finish(); auto buf = bufpl.getBufferSharedPointer(); str = std::string( diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 1934b02b..ed603c3b 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -477,9 +477,7 @@ test_8(QPDF& pdf, char const* arg2) } Pl_Buffer p1("buffer"); Pl_Flate p2("compress", &p1, Pl_Flate::a_deflate); - p2.write( - QUtil::unsigned_char_pointer("new data for stream\n"), - 20); // no null! + p2 << "new data for stream\n"; p2.finish(); auto b = p1.getBufferSharedPointer(); // This is a bogus way to use StreamDataProvider, but it does @@ -1021,9 +1019,7 @@ test_27(QPDF& pdf, char const* arg2) { // Local scope Pl_Buffer pl("buffer"); - pl.write( - QUtil::unsigned_char_pointer("new data for stream\n"), - 20); // no null! + pl.writeCStr("new data for stream\n"); pl.finish(); auto b = pl.getBufferSharedPointer(); Provider* provider = new Provider(b); @@ -1050,9 +1046,7 @@ test_27(QPDF& pdf, char const* arg2) { // Local scope Pl_Buffer pl("buffer"); - pl.write( - QUtil::unsigned_char_pointer("more data for stream\n"), - 21); // no null! + pl.writeCStr("more data for stream\n"); pl.finish(); auto b = pl.getBufferSharedPointer(); Provider* provider = new Provider(b); @@ -2648,7 +2642,8 @@ test_76(QPDF& pdf, char const* arg2) auto efs2 = QPDFEFStreamObjectHelper::createEFStream(pdf, "from string"); efs2.setSubtype("text/plain"); Pl_Buffer p("buffer"); - p.write(QUtil::unsigned_char_pointer("from buffer"), 11); + // exercise Pipeline::operator<<(std::string const&) + p << std::string("from buffer"); p.finish(); auto efs3 = QPDFEFStreamObjectHelper::createEFStream( pdf, p.getBufferSharedPointer()); @@ -2700,7 +2695,7 @@ test_78(QPDF& pdf, char const* arg2) // Test functional versions of replaceStreamData() auto f1 = [](Pipeline* p) { - p->write(QUtil::unsigned_char_pointer("potato"), 6); + p->writeCStr("potato"); p->finish(); }; auto f2 = [](Pipeline* p, bool suppress_warnings, bool will_retry) { @@ -2712,7 +2707,7 @@ test_78(QPDF& pdf, char const* arg2) if (!suppress_warnings) { std::cerr << "warning" << std::endl; } - p->write(QUtil::unsigned_char_pointer("salad"), 5); + p->writeCStr("salad"); p->finish(); std::cerr << "f2 done" << std::endl; return true; @@ -2767,7 +2762,7 @@ test_79(QPDF& pdf, char const* arg2) // Use a provider Pl_Buffer b("buffer"); - b.write(QUtil::unsigned_char_pointer("from buffer"), 11); + b.writeCStr("from buffer"); b.finish(); auto bp = b.getBufferSharedPointer(); auto s3 = QPDFObjectHandle::newStream(&pdf, bp);