From 2fa581537b068e5ddcaee68fd7b92e290fc5fc53 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 20 May 2023 13:34:53 +0100 Subject: [PATCH] Use auto when initializing with a cast --- libqpdf/InsecureRandomDataProvider.cc | 2 +- libqpdf/JSON.cc | 14 +++++++------- libqpdf/Pl_ASCIIHexDecoder.cc | 2 +- libqpdf/Pl_DCT.cc | 12 ++++++------ libqpdf/Pl_LZWDecoder.cc | 2 +- libqpdf/Pl_RunLength.cc | 4 ++-- libqpdf/QPDFFormFieldObjectHelper.cc | 2 +- libqpdf/QPDF_Stream.cc | 2 +- libqpdf/QPDF_optimization.cc | 2 +- libtests/qintc.cc | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libqpdf/InsecureRandomDataProvider.cc b/libqpdf/InsecureRandomDataProvider.cc index 90a548ee..ed62d6c7 100644 --- a/libqpdf/InsecureRandomDataProvider.cc +++ b/libqpdf/InsecureRandomDataProvider.cc @@ -24,7 +24,7 @@ InsecureRandomDataProvider::random() // Seed the random number generator with something simple, but // just to be interesting, don't use the unmodified current // time. It would be better if this were a more secure seed. - unsigned int seed = + auto seed = static_cast(QUtil::get_current_time() ^ 0xcccc); #ifdef HAVE_RANDOM ::srandom(seed); diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index fbf06f88..5f76f1ec 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -294,7 +294,7 @@ JSON::addDictionaryMember(std::string const& key, JSON const& val) bool JSON::checkDictionaryKeySeen(std::string const& key) { - JSON_dictionary* obj = dynamic_cast(this->m->value.get()); + auto* obj = dynamic_cast(this->m->value.get()); if (nullptr == obj) { throw std::logic_error( "JSON::checkDictionaryKey called on non-dictionary"); @@ -315,7 +315,7 @@ JSON::makeArray() JSON JSON::addArrayElement(JSON const& val) { - JSON_array* arr = dynamic_cast(this->m->value.get()); + auto* arr = dynamic_cast(this->m->value.get()); if (nullptr == arr) { throw std::runtime_error("JSON::addArrayElement called on non-array"); } @@ -470,13 +470,13 @@ JSON::checkSchemaInternal( std::list& errors, std::string prefix) { - JSON_array* this_arr = dynamic_cast(this_v); - JSON_dictionary* this_dict = dynamic_cast(this_v); + auto* this_arr = dynamic_cast(this_v); + auto* this_dict = dynamic_cast(this_v); - JSON_array* sch_arr = dynamic_cast(sch_v); - JSON_dictionary* sch_dict = dynamic_cast(sch_v); + auto* sch_arr = dynamic_cast(sch_v); + auto* sch_dict = dynamic_cast(sch_v); - JSON_string* sch_str = dynamic_cast(sch_v); + auto* sch_str = dynamic_cast(sch_v); std::string err_prefix; if (prefix.empty()) { diff --git a/libqpdf/Pl_ASCIIHexDecoder.cc b/libqpdf/Pl_ASCIIHexDecoder.cc index 5590efba..3548f33e 100644 --- a/libqpdf/Pl_ASCIIHexDecoder.cc +++ b/libqpdf/Pl_ASCIIHexDecoder.cc @@ -76,7 +76,7 @@ Pl_ASCIIHexDecoder::flush() b[i] = this->inbuf[i] - '0'; } } - unsigned char ch = static_cast((b[0] << 4) + b[1]); + auto ch = static_cast((b[0] << 4) + b[1]); QTC::TC( "libtests", diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc index c01398ad..299b48b1 100644 --- a/libqpdf/Pl_DCT.cc +++ b/libqpdf/Pl_DCT.cc @@ -24,7 +24,7 @@ namespace static void error_handler(j_common_ptr cinfo) { - qpdf_jpeg_error_mgr* jerr = + auto* jerr = reinterpret_cast(cinfo->err); char buf[JMSG_LENGTH_MAX]; (*cinfo->err->format_message)(cinfo, buf); @@ -167,7 +167,7 @@ static boolean empty_pipeline_output_buffer(j_compress_ptr cinfo) { QTC::TC("libtests", "Pl_DCT empty_pipeline_output_buffer"); - dct_pipeline_dest* dest = reinterpret_cast(cinfo->dest); + auto* dest = reinterpret_cast(cinfo->dest); dest->next->write(dest->buffer, dest->size); dest->pub.next_output_byte = dest->buffer; dest->pub.free_in_buffer = dest->size; @@ -178,7 +178,7 @@ static void term_pipeline_destination(j_compress_ptr cinfo) { QTC::TC("libtests", "Pl_DCT term_pipeline_destination"); - dct_pipeline_dest* dest = reinterpret_cast(cinfo->dest); + auto* dest = reinterpret_cast(cinfo->dest); dest->next->write(dest->buffer, dest->size - dest->pub.free_in_buffer); } @@ -192,7 +192,7 @@ jpeg_pipeline_dest( reinterpret_cast(cinfo), JPOOL_PERMANENT, sizeof(dct_pipeline_dest))); - dct_pipeline_dest* dest = reinterpret_cast(cinfo->dest); + auto* dest = reinterpret_cast(cinfo->dest); dest->pub.init_destination = init_pipeline_destination; dest->pub.empty_output_buffer = empty_pipeline_output_buffer; dest->pub.term_destination = term_pipeline_destination; @@ -261,7 +261,7 @@ jpeg_buffer_src(j_decompress_ptr cinfo, Buffer* buffer) void Pl_DCT::compress(void* cinfo_p, Buffer* b) { - struct jpeg_compress_struct* cinfo = + auto* cinfo = reinterpret_cast(cinfo_p); #if ( \ @@ -316,7 +316,7 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) void Pl_DCT::decompress(void* cinfo_p, Buffer* b) { - struct jpeg_decompress_struct* cinfo = + auto* cinfo = reinterpret_cast(cinfo_p); #if ( \ diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc index 1c2d6807..3356ea4f 100644 --- a/libqpdf/Pl_LZWDecoder.cc +++ b/libqpdf/Pl_LZWDecoder.cc @@ -189,7 +189,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) } if (code < 256) { - unsigned char ch = static_cast(code); + auto ch = static_cast(code); getNext()->write(&ch, 1); } else { unsigned int idx = code - 258; diff --git a/libqpdf/Pl_RunLength.cc b/libqpdf/Pl_RunLength.cc index 786e2e86..d60da70a 100644 --- a/libqpdf/Pl_RunLength.cc +++ b/libqpdf/Pl_RunLength.cc @@ -127,11 +127,11 @@ Pl_RunLength::flush_encode() throw std::logic_error( "Pl_RunLength: invalid length in flush_encode for run"); } - unsigned char ch = static_cast(257 - this->m->length); + auto ch = static_cast(257 - this->m->length); this->getNext()->write(&ch, 1); this->getNext()->write(&this->m->buf[0], 1); } else if (this->m->length > 0) { - unsigned char ch = static_cast(this->m->length - 1); + auto ch = static_cast(this->m->length - 1); this->getNext()->write(&ch, 1); this->getNext()->write(this->m->buf, this->m->length); } diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index 93dc0e63..7712cab2 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -611,7 +611,7 @@ ValueSetter::writeAppearance() // Write one or more lines, centered vertically, possibly with // one row highlighted. - size_t max_rows = static_cast((bbox.ury - bbox.lly) / tfh); + auto max_rows = static_cast((bbox.ury - bbox.lly) / tfh); bool highlight = false; size_t highlight_idx = 0; diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 8e2e16c5..4ceeab48 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -557,7 +557,7 @@ QPDF_Stream::pipeStreamData( if (decode_pipeline) { pipeline = decode_pipeline; } - Pl_Flate* flate = dynamic_cast(pipeline); + auto* flate = dynamic_cast(pipeline); if (flate != nullptr) { flate->setWarnCallback( [this](char const* msg, int code) { warn(msg); }); diff --git a/libqpdf/QPDF_optimization.cc b/libqpdf/QPDF_optimization.cc index 41204fbd..9130287a 100644 --- a/libqpdf/QPDF_optimization.cc +++ b/libqpdf/QPDF_optimization.cc @@ -115,7 +115,7 @@ QPDF::optimize( } ObjUser root_ou = ObjUser(ObjUser::ou_root); - QPDFObjGen root_og = QPDFObjGen(root.getObjGen()); + auto root_og = QPDFObjGen(root.getObjGen()); this->m->obj_user_to_objects[root_ou].insert(root_og); this->m->object_to_obj_users[root_og].insert(root_ou); diff --git a/libtests/qintc.cc b/libtests/qintc.cc index 0cf3924f..5b985644 100644 --- a/libtests/qintc.cc +++ b/libtests/qintc.cc @@ -74,7 +74,7 @@ main() uint64_t ul1 = 1099511627776LL; // Too big for 32-bit uint64_t ul2 = 12345; // Fits into 32-bit int32_t i2 = 81; // Fits in char and uchar - signed char c1 = static_cast('\xf7'); // Signed value when char + auto c1 = static_cast('\xf7'); // Signed value when char char c2 = 'W'; // char; may be signed or unsigned // Verify i1 and u1 have same bit pattern