2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-13 15:42:21 +00:00

Use auto when initialializing with new

This commit is contained in:
m-holger 2023-05-20 13:24:10 +01:00
parent d0682f0f60
commit 41ec7eda54
16 changed files with 28 additions and 28 deletions

View File

@ -166,7 +166,7 @@ add_page(
// mode. Since we are not specifying, QPDFWriter will compress // mode. Since we are not specifying, QPDFWriter will compress
// with /FlateDecode if we don't provide any other form of // with /FlateDecode if we don't provide any other form of
// compression. // compression.
ImageProvider* p = new ImageProvider(color_space, filter); auto* p = new ImageProvider(color_space, filter);
std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p); std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p);
size_t width = p->getWidth(); size_t width = p->getWidth();
size_t height = p->getHeight(); size_t height = p->getHeight();
@ -286,7 +286,7 @@ check(
if (!this_errors) { if (!this_errors) {
// Check image data // Check image data
auto actual_data = image.getStreamData(qpdf_dl_all); auto actual_data = image.getStreamData(qpdf_dl_all);
ImageProvider* p = new ImageProvider(desired_color_space, "null"); auto* p = new ImageProvider(desired_color_space, "null");
std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p); std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p);
Pl_Buffer b_p("get image data"); Pl_Buffer b_p("get image data");
provider->provideStreamData(QPDFObjGen(), &b_p); provider->provideStreamData(QPDFObjGen(), &b_p);

View File

@ -409,7 +409,7 @@ process(
// Create a single StreamReplacer instance. The interface requires // Create a single StreamReplacer instance. The interface requires
// a std::shared_ptr in various places, so allocate a StreamReplacer // a std::shared_ptr in various places, so allocate a StreamReplacer
// and stash it in a std::shared_ptr. // and stash it in a std::shared_ptr.
StreamReplacer* replacer = new StreamReplacer(&qpdf); auto* replacer = new StreamReplacer(&qpdf);
std::shared_ptr<QPDFObjectHandle::StreamDataProvider> p(replacer); std::shared_ptr<QPDFObjectHandle::StreamDataProvider> p(replacer);
for (auto& o: qpdf.getAllObjects()) { for (auto& o: qpdf.getAllObjects()) {

View File

@ -124,7 +124,7 @@ main(int argc, char* argv[])
QPDF qpdf; QPDF qpdf;
qpdf.processFile(infilename, password); qpdf.processFile(infilename, password);
ImageInverter* inv = new ImageInverter; auto* inv = new ImageInverter;
auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(inv); auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(inv);
// For each page... // For each page...

View File

@ -45,7 +45,7 @@ Pl_Buffer::getBuffer()
} }
auto size = this->m->data.length(); auto size = this->m->data.length();
Buffer* b = new Buffer(size); auto* b = new Buffer(size);
if (size > 0) { if (size > 0) {
unsigned char* p = b->getBuffer(); unsigned char* p = b->getBuffer();
memcpy(p, this->m->data.data(), size); memcpy(p, this->m->data.data(), size);

View File

@ -264,7 +264,7 @@ QPDF::create()
void void
QPDF::processFile(char const* filename, char const* password) QPDF::processFile(char const* filename, char const* password)
{ {
FileInputSource* fi = new FileInputSource(filename); auto* fi = new FileInputSource(filename);
processInputSource(std::shared_ptr<InputSource>(fi), password); processInputSource(std::shared_ptr<InputSource>(fi), password);
} }
@ -272,7 +272,7 @@ void
QPDF::processFile( QPDF::processFile(
char const* description, FILE* filep, bool close_file, char const* password) char const* description, FILE* filep, bool close_file, char const* password)
{ {
FileInputSource* fi = new FileInputSource(description, filep, close_file); auto* fi = new FileInputSource(description, filep, close_file);
processInputSource(std::shared_ptr<InputSource>(fi), password); processInputSource(std::shared_ptr<InputSource>(fi), password);
} }

View File

@ -997,7 +997,7 @@ void
QPDFWriter::activatePipelineStack(PipelinePopper& pp) QPDFWriter::activatePipelineStack(PipelinePopper& pp)
{ {
std::string stack_id("stack " + std::to_string(this->m->next_stack_id)); std::string stack_id("stack " + std::to_string(this->m->next_stack_id));
Pl_Count* c = auto* c =
new Pl_Count(stack_id.c_str(), this->m->pipeline_stack.back()); new Pl_Count(stack_id.c_str(), this->m->pipeline_stack.back());
++this->m->next_stack_id; ++this->m->next_stack_id;
this->m->pipeline_stack.push_back(c); this->m->pipeline_stack.push_back(c);
@ -1030,7 +1030,7 @@ QPDFWriter::PipelinePopper::~PipelinePopper()
qw->m->md5_pipeline = nullptr; qw->m->md5_pipeline = nullptr;
} }
qw->m->pipeline_stack.pop_back(); qw->m->pipeline_stack.pop_back();
Pl_Buffer* buf = dynamic_cast<Pl_Buffer*>(p); auto* buf = dynamic_cast<Pl_Buffer*>(p);
if (bp && buf) { if (bp && buf) {
*bp = buf->getBufferSharedPointer(); *bp = buf->getBufferSharedPointer();
} }

View File

@ -83,7 +83,7 @@ QPDF_Array::copy(bool shallow)
return do_create(new QPDF_Array(*this)); return do_create(new QPDF_Array(*this));
} else { } else {
if (sparse) { if (sparse) {
QPDF_Array* result = new QPDF_Array(); auto* result = new QPDF_Array();
result->sp_size = sp_size; result->sp_size = sp_size;
for (auto const& element: sp_elements) { for (auto const& element: sp_elements) {
auto const& obj = element.second; auto const& obj = element.second;

View File

@ -106,7 +106,7 @@ qpdf_data
qpdf_init() qpdf_init()
{ {
QTC::TC("qpdf", "qpdf-c called qpdf_init"); QTC::TC("qpdf", "qpdf-c called qpdf_init");
qpdf_data qpdf = new _qpdf_data(); auto qpdf = new _qpdf_data();
qpdf->qpdf = QPDF::create(); qpdf->qpdf = QPDF::create();
return qpdf; return qpdf;
} }

View File

@ -74,7 +74,7 @@ main(int argc, char* argv[])
FILE* infile = QUtil::safe_fopen(infilename, "rb"); FILE* infile = QUtil::safe_fopen(infilename, "rb");
FILE* outfile = QUtil::safe_fopen(outfilename, "wb"); FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
unsigned char* key = new unsigned char[keylen]; auto* key = new unsigned char[keylen];
for (unsigned int i = 0; i < strlen(hexkey); i += 2) { for (unsigned int i = 0; i < strlen(hexkey); i += 2) {
char t[3]; char t[3];
t[0] = hexkey[i]; t[0] = hexkey[i];
@ -85,8 +85,8 @@ main(int argc, char* argv[])
key[i / 2] = static_cast<unsigned char>(val); key[i / 2] = static_cast<unsigned char>(val);
} }
Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile); auto* out = new Pl_StdioFile("stdout", outfile);
Pl_AES_PDF* aes = new Pl_AES_PDF("aes_128_cbc", out, encrypt, key, keylen); auto* aes = new Pl_AES_PDF("aes_128_cbc", out, encrypt, key, keylen);
delete[] key; delete[] key;
key = nullptr; key = nullptr;
if (!cbc_mode) { if (!cbc_mode) {

View File

@ -141,7 +141,7 @@ test()
unsigned char ch = 0; unsigned char ch = 0;
bit_offset = 7; bit_offset = 7;
Pl_Buffer* bp = new Pl_Buffer("buffer"); auto* bp = new Pl_Buffer("buffer");
test_write_bits(ch, bit_offset, 30UL, 5, bp); test_write_bits(ch, bit_offset, 30UL, 5, bp);
test_write_bits(ch, bit_offset, 10UL, 4, bp); test_write_bits(ch, bit_offset, 10UL, 4, bp);

View File

@ -28,7 +28,7 @@ run(char const* filename)
Pipeline* inf2 = new Pl_Flate("inf2", out2, Pl_Flate::a_inflate); Pipeline* inf2 = new Pl_Flate("inf2", out2, Pl_Flate::a_inflate);
// Count bytes written to o3 // Count bytes written to o3
Pl_Count* count3 = new Pl_Count("count3", out3); auto* count3 = new Pl_Count("count3", out3);
// Do both simultaneously // Do both simultaneously
Pipeline* inf3 = new Pl_Flate("inf3", count3, Pl_Flate::a_inflate); Pipeline* inf3 = new Pl_Flate("inf3", count3, Pl_Flate::a_inflate);

View File

@ -72,7 +72,7 @@ test_ph()
ObjectHolder oh0; ObjectHolder oh0;
{ {
std::cout << "hello" << std::endl; std::cout << "hello" << std::endl;
Object* o1 = new Object; auto* o1 = new Object;
ObjectHolder oh1(o1); ObjectHolder oh1(o1);
std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl; std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl;
ObjectHolder oh2(oh1); ObjectHolder oh2(oh1);
@ -95,7 +95,7 @@ test_ph()
} }
ol1.push_back(oh3); ol1.push_back(oh3);
ol1.push_back(oh3); ol1.push_back(oh3);
Object* o3 = new Object; auto* o3 = new Object;
oh0 = o3; oh0 = o3;
PointerHolder<Object const> oh6(new Object()); PointerHolder<Object const> oh6(new Object());
oh6->hello(); oh6->hello();

View File

@ -41,7 +41,7 @@ main(int argc, char* argv[])
char* outfilename = argv[3]; char* outfilename = argv[3];
unsigned int hexkeylen = QIntC::to_uint(strlen(hexkey)); unsigned int hexkeylen = QIntC::to_uint(strlen(hexkey));
unsigned int keylen = hexkeylen / 2; unsigned int keylen = hexkeylen / 2;
unsigned char* key = new unsigned char[keylen + 1]; auto* key = new unsigned char[keylen + 1];
key[keylen] = '\0'; key[keylen] = '\0';
FILE* infile = QUtil::safe_fopen(infilename, "rb"); FILE* infile = QUtil::safe_fopen(infilename, "rb");
@ -56,9 +56,9 @@ main(int argc, char* argv[])
} }
FILE* outfile = QUtil::safe_fopen(outfilename, "wb"); FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile); auto* out = new Pl_StdioFile("stdout", outfile);
// Use a small buffer size (64) for testing // Use a small buffer size (64) for testing
Pl_RC4* rc4 = new Pl_RC4("rc4", out, key, QIntC::to_int(keylen), 64U); auto* rc4 = new Pl_RC4("rc4", out, key, QIntC::to_int(keylen), 64U);
delete[] key; delete[] key;
// 64 < buffer size < 512, buffer_size is not a power of 2 for testing // 64 < buffer size < 512, buffer_size is not a power of 2 for testing

View File

@ -499,7 +499,7 @@ test_8(QPDF& pdf, char const* arg2)
auto b = p1.getBufferSharedPointer(); auto b = p1.getBufferSharedPointer();
// This is a bogus way to use StreamDataProvider, but it does // This is a bogus way to use StreamDataProvider, but it does
// adequately test its functionality. // adequately test its functionality.
Provider* provider = new Provider(b); auto* provider = new Provider(b);
auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(provider); auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(provider);
qstream.replaceStreamData( qstream.replaceStreamData(
p, p,
@ -1068,7 +1068,7 @@ test_27(QPDF& pdf, char const* arg2)
pl.writeCStr("new data for stream\n"); pl.writeCStr("new data for stream\n");
pl.finish(); pl.finish();
auto b = pl.getBufferSharedPointer(); auto b = pl.getBufferSharedPointer();
Provider* provider = new Provider(b); auto* provider = new Provider(b);
p1 = decltype(p1)(provider); p1 = decltype(p1)(provider);
} }
// Create a stream that uses a provider in empty1 and copy it // Create a stream that uses a provider in empty1 and copy it
@ -1095,7 +1095,7 @@ test_27(QPDF& pdf, char const* arg2)
pl.writeCStr("more data for stream\n"); pl.writeCStr("more data for stream\n");
pl.finish(); pl.finish();
auto b = pl.getBufferSharedPointer(); auto b = pl.getBufferSharedPointer();
Provider* provider = new Provider(b); auto* provider = new Provider(b);
p2 = decltype(p2)(provider); p2 = decltype(p2)(provider);
} }
QPDF empty3; QPDF empty3;

View File

@ -218,7 +218,7 @@ create_pdf(char const* filename)
image_dict.replaceKey("/BitsPerComponent", newInteger(8)); image_dict.replaceKey("/BitsPerComponent", newInteger(8));
image_dict.replaceKey("/Width", newInteger(width)); image_dict.replaceKey("/Width", newInteger(width));
image_dict.replaceKey("/Height", newInteger(height)); image_dict.replaceKey("/Height", newInteger(height));
ImageProvider* p = new ImageProvider(pageno); auto* p = new ImageProvider(pageno);
std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p); std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p);
image.replaceStreamData( image.replaceStreamData(
provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());

View File

@ -190,7 +190,7 @@ process(char const* filename, bool include_ignorable, size_t max_len)
std::shared_ptr<InputSource> is; std::shared_ptr<InputSource> is;
// Tokenize file, skipping streams // Tokenize file, skipping streams
FileInputSource* fis = new FileInputSource(filename); auto* fis = new FileInputSource(filename);
is = std::shared_ptr<InputSource>(fis); is = std::shared_ptr<InputSource>(fis);
dump_tokens(is, "FILE", max_len, include_ignorable, true, false); dump_tokens(is, "FILE", max_len, include_ignorable, true, false);
@ -203,7 +203,7 @@ process(char const* filename, bool include_ignorable, size_t max_len)
Pl_Buffer plb("buffer"); Pl_Buffer plb("buffer");
page.pipeContents(&plb); page.pipeContents(&plb);
auto content_data = plb.getBufferSharedPointer(); auto content_data = plb.getBufferSharedPointer();
BufferInputSource* bis = auto* bis =
new BufferInputSource("content data", content_data.get()); new BufferInputSource("content data", content_data.get());
is = std::shared_ptr<InputSource>(bis); is = std::shared_ptr<InputSource>(bis);
dump_tokens( dump_tokens(
@ -220,7 +220,7 @@ process(char const* filename, bool include_ignorable, size_t max_len)
if (obj.isStream() && obj.getDict().getKey("/Type").isName() && if (obj.isStream() && obj.getDict().getKey("/Type").isName() &&
obj.getDict().getKey("/Type").getName() == "/ObjStm") { obj.getDict().getKey("/Type").getName() == "/ObjStm") {
std::shared_ptr<Buffer> b = obj.getStreamData(qpdf_dl_specialized); std::shared_ptr<Buffer> b = obj.getStreamData(qpdf_dl_specialized);
BufferInputSource* bis = auto* bis =
new BufferInputSource("object stream data", b.get()); new BufferInputSource("object stream data", b.get());
is = std::shared_ptr<InputSource>(bis); is = std::shared_ptr<InputSource>(bis);
dump_tokens( dump_tokens(