From 92d3cbecd4ea375d8de95bffc0fe8651c698f568 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 16 Apr 2020 11:43:37 -0400 Subject: Fix warnings reported by -Wshadow=local (fixes #431) --- libqpdf/Pl_DCT.cc | 5 +++-- libqpdf/QPDFObjectHandle.cc | 8 ++++---- libqpdf/QPDFPageObjectHelper.cc | 14 +++++--------- libqpdf/QPDFTokenizer.cc | 12 +++++++----- libqpdf/QPDFWriter.cc | 29 ++++++++++++++--------------- libqpdf/QPDF_Stream.cc | 24 +++++++++++++----------- libqpdf/QPDF_encryption.cc | 8 ++++---- libqpdf/QPDF_linearization.cc | 6 +++--- libqpdf/QUtil.cc | 20 ++++++++++---------- 9 files changed, 63 insertions(+), 63 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc index de7e1a5e..7231486d 100644 --- a/libqpdf/Pl_DCT.cc +++ b/libqpdf/Pl_DCT.cc @@ -302,8 +302,9 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) unsigned int width = cinfo->image_width * QIntC::to_uint(cinfo->input_components); size_t expected_size = - cinfo->image_height * cinfo->image_width * - QIntC::to_uint(cinfo->input_components); + QIntC::to_size(cinfo->image_height) * + QIntC::to_size(cinfo->image_width) * + QIntC::to_size(cinfo->input_components); if (b->getSize() != expected_size) { throw std::runtime_error( diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index ab77fb73..85493680 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1607,12 +1607,12 @@ QPDFObjectHandle::pipeContentStreams( std::string og = QUtil::int_to_string(stream.getObjectID()) + " " + QUtil::int_to_string(stream.getGeneration()); - std::string description = "content stream object " + og; + std::string w_description = "content stream object " + og; if (! stream.pipeStreamData(p, 0, qpdf_dl_specialized)) { QTC::TC("qpdf", "QPDFObjectHandle errors in parsecontent"); throw QPDFExc(qpdf_e_damaged_pdf, "content stream", - description, 0, + w_description, 0, "errors while decoding content stream"); } } @@ -1685,13 +1685,13 @@ QPDFObjectHandle::parseContentStream_data( ParserCallbacks* callbacks, QPDF* context) { - size_t length = stream_data->getSize(); + size_t stream_length = stream_data->getSize(); PointerHolder input = new BufferInputSource(description, stream_data.getPointer()); QPDFTokenizer tokenizer; tokenizer.allowEOF(); bool empty = false; - while (QIntC::to_size(input->tell()) < length) + while (QIntC::to_size(input->tell()) < stream_length) { // Read a token and seek to the beginning. The offset we get // from this process is the beginning of the next diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index 8e0aac06..b7da816e 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -76,10 +76,8 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict) dict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); dict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Image")); std::set keys = odict.getKeys(); - for (std::set::iterator iter = keys.begin(); - iter != keys.end(); ++iter) + for (auto key: keys) { - std::string key = *iter; QPDFObjectHandle value = odict.getKey(key); if (key == "/BPC") { @@ -176,14 +174,12 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict) { filters = value.getArrayAsVector(); } - for (std::vector::iterator iter = - filters.begin(); - iter != filters.end(); ++iter) + for (auto& iter: filters) { std::string name; - if ((*iter).isName()) + if (iter.isName()) { - name = (*iter).getName(); + name = iter.getName(); } if (name == "/AHx") { @@ -219,7 +215,7 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict) } if (! name.empty()) { - *iter = QPDFObjectHandle::newName(name); + iter = QPDFObjectHandle::newName(name); } } if (value.isName() && (filters.size() == 1)) diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc index 207d62d8..4217575c 100644 --- a/libqpdf/QPDFTokenizer.cc +++ b/libqpdf/QPDFTokenizer.cc @@ -175,8 +175,8 @@ QPDFTokenizer::resolveLiteral() num[0] = this->m->val.at(i+1); num[1] = this->m->val.at(i+2); num[2] = '\0'; - char ch = static_cast(strtol(num, 0, 16)); - if (ch == '\0') + char ch2 = static_cast(strtol(num, 0, 16)); + if (ch2 == '\0') { this->m->type = tt_bad; QTC::TC("qpdf", "QPDFTokenizer null in name"); @@ -186,7 +186,7 @@ QPDFTokenizer::resolveLiteral() } else { - nval.append(1, ch); + nval.append(1, ch2); } i += 2; } @@ -719,7 +719,7 @@ QPDFTokenizer::findEI(PointerHolder input) for (std::string::iterator iter = value.begin(); iter != value.end(); ++iter) { - char ch = *iter; + signed char ch = *iter; if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) @@ -729,8 +729,10 @@ QPDFTokenizer::findEI(PointerHolder input) // alphabetic characters. found_alpha = true; } - else if (((ch < 32) && (! isSpace(ch))) || (ch > 127)) + else if ((ch < 32) && (! isSpace(ch))) { + // ch is signed, so characters outside of + // 7-bit will be < 0. found_non_printable = true; break; } diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index cdab9db1..15999436 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -1790,14 +1790,14 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, } } bool normalize = false; - bool compress = false; + bool compress_stream = false; bool uncompress = false; if (is_metadata && ((! this->m->encrypted) || (this->m->encrypt_metadata == false))) { QTC::TC("qpdf", "QPDFWriter not compressing metadata"); filter = true; - compress = false; + compress_stream = false; uncompress = true; } else if (this->m->normalize_content && @@ -1808,7 +1808,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, } else if (filter && this->m->compress_streams) { - compress = true; + compress_stream = true; QTC::TC("qpdf", "QPDFWriter compressing uncompressed stream"); } @@ -1825,7 +1825,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, object.pipeStreamData( this->m->pipeline, (((filter && normalize) ? qpdf_ef_normalize : 0) | - ((filter && compress) ? qpdf_ef_compress : 0)), + ((filter && compress_stream) ? qpdf_ef_compress : 0)), (filter ? (uncompress ? qpdf_dl_all : this->m->stream_decode_level) : qpdf_dl_none), false, (attempt == 1)); @@ -1845,7 +1845,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, } else { - compress = false; + compress_stream = false; } this->m->cur_stream_length = stream_data->getSize(); @@ -1856,7 +1856,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, } adjustAESStreamLength(this->m->cur_stream_length); unparseObject(stream_dict, 0, flags, - this->m->cur_stream_length, compress); + this->m->cur_stream_length, compress_stream); unsigned char last_char = '\0'; writeString("\nstream\n"); { @@ -2330,11 +2330,10 @@ QPDFWriter::initializeSpecialStreams() contents_objects.push_back(contents.getObjGen()); } - for (std::vector::iterator iter = contents_objects.begin(); - iter != contents_objects.end(); ++iter) + for (auto const& c: contents_objects) { - this->m->contents_to_page_seq[*iter] = num; - this->m->normalized_streams.insert(*iter); + this->m->contents_to_page_seq[c] = num; + this->m->normalized_streams.insert(c); } } } @@ -3462,9 +3461,9 @@ QPDFWriter::writeLinearized() else { // Make the file size the same. - qpdf_offset_t pos = this->m->pipeline->getCount(); writePad( - QIntC::to_int(second_xref_end + hint_length - 1 - pos)); + QIntC::to_int(second_xref_end + hint_length - + 1 - this->m->pipeline->getCount())); writeString("\n"); // If this assertion fails, maybe we didn't have @@ -3507,7 +3506,7 @@ QPDFWriter::writeLinearized() // Save hint offset since it will be set to zero by // calling openObject. - qpdf_offset_t hint_offset = this->m->xref[hint_id].getOffset(); + qpdf_offset_t hint_offset1 = this->m->xref[hint_id].getOffset(); // Write hint stream to a buffer { @@ -3519,12 +3518,12 @@ QPDFWriter::writeLinearized() hint_length = QIntC::to_offset(hint_buffer->getSize()); // Restore hint offset - this->m->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0); + this->m->xref[hint_id] = QPDFXRefEntry(1, hint_offset1, 0); if (lin_pass1_file) { // Write some debugging information fprintf(lin_pass1_file, "%% hint_offset=%s\n", - QUtil::int_to_string(hint_offset).c_str()); + QUtil::int_to_string(hint_offset1).c_str()); fprintf(lin_pass1_file, "%% hint_length=%s\n", QUtil::int_to_string(hint_length).c_str()); fprintf(lin_pass1_file, "%% second_xref_offset=%s\n", diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 37ff9417..e4a3c039 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -555,12 +555,14 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, to_delete.push_back(pipeline); } - for (std::vector::reverse_iterator iter = filters.rbegin(); - iter != filters.rend(); ++iter) + for (std::vector::reverse_iterator f_iter = + filters.rbegin(); + f_iter != filters.rend(); ++f_iter) { - std::string const& filter = *iter; + std::string const& filter_name = *f_iter; - if ((filter == "/FlateDecode") || (filter == "/LZWDecode")) + if ((filter_name == "/FlateDecode") || + (filter_name == "/LZWDecode")) { if ((predictor >= 10) && (predictor <= 15)) { @@ -584,39 +586,39 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, } } - if (filter == "/Crypt") + if (filter_name == "/Crypt") { // Ignore -- handled by pipeStreamData } - else if (filter == "/FlateDecode") + else if (filter_name == "/FlateDecode") { pipeline = new Pl_Flate("stream inflate", pipeline, Pl_Flate::a_inflate); to_delete.push_back(pipeline); } - else if (filter == "/ASCII85Decode") + else if (filter_name == "/ASCII85Decode") { pipeline = new Pl_ASCII85Decoder("ascii85 decode", pipeline); to_delete.push_back(pipeline); } - else if (filter == "/ASCIIHexDecode") + else if (filter_name == "/ASCIIHexDecode") { pipeline = new Pl_ASCIIHexDecoder("asciiHex decode", pipeline); to_delete.push_back(pipeline); } - else if (filter == "/LZWDecode") + else if (filter_name == "/LZWDecode") { pipeline = new Pl_LZWDecoder("lzw decode", pipeline, early_code_change); to_delete.push_back(pipeline); } - else if (filter == "/RunLengthDecode") + else if (filter_name == "/RunLengthDecode") { pipeline = new Pl_RunLength("runlength decode", pipeline, Pl_RunLength::a_decode); to_delete.push_back(pipeline); } - else if (filter == "/DCTDecode") + else if (filter_name == "/DCTDecode") { pipeline = new Pl_DCT("DCT decode", pipeline); to_delete.push_back(pipeline); diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 9880face..48351122 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -322,10 +322,10 @@ hash_V5(std::string const& password, int next_hash = ((E_mod_3 == 0) ? 256 : (E_mod_3 == 1) ? 384 : 512); - Pl_SHA2 hash(next_hash); - hash.write(QUtil::unsigned_char_pointer(E), E.length()); - hash.finish(); - K = hash.getRawDigest(); + Pl_SHA2 sha2(next_hash); + sha2.write(QUtil::unsigned_char_pointer(E), E.length()); + sha2.finish(); + K = sha2.getRawDigest(); if (round_number >= 64) { diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 763b8ee0..3dff1c17 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -374,9 +374,9 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) QTC::TC("qpdf", "QPDF hint table length indirect"); // Force resolution (void) length_obj.getIntValue(); - ObjCache& oc = this->m->obj_cache[length_obj.getObjGen()]; - min_end_offset = oc.end_before_space; - max_end_offset = oc.end_after_space; + ObjCache& oc2 = this->m->obj_cache[length_obj.getObjGen()]; + min_end_offset = oc2.end_before_space; + max_end_offset = oc2.end_after_space; } else { diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index c3c4f12f..072a939c 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -812,7 +812,7 @@ QUtil::toUTF8(unsigned long uval) // maximum value that will fit in the current number of bytes unsigned char maxval = 0x3f; // six bits - while (uval > maxval) + while (uval > QIntC::to_ulong(maxval)) { // Assign low six bits plus 10000000 to lowest unused // byte position, then shift @@ -2163,12 +2163,12 @@ QUtil::win_ansi_to_utf8(std::string const& val) for (unsigned int i = 0; i < len; ++i) { unsigned char ch = static_cast(val.at(i)); - unsigned short val = ch; + unsigned short ch_short = ch; if ((ch >= 128) && (ch <= 160)) { - val = win_ansi_to_unicode[ch - 128]; + ch_short = win_ansi_to_unicode[ch - 128]; } - result += QUtil::toUTF8(val); + result += QUtil::toUTF8(ch_short); } return result; } @@ -2181,12 +2181,12 @@ QUtil::mac_roman_to_utf8(std::string const& val) for (unsigned int i = 0; i < len; ++i) { unsigned char ch = static_cast(val.at(i)); - unsigned short val = ch; + unsigned short ch_short = ch; if (ch >= 128) { - val = mac_roman_to_unicode[ch - 128]; + ch_short = mac_roman_to_unicode[ch - 128]; } - result += QUtil::toUTF8(val); + result += QUtil::toUTF8(ch_short); } return result; } @@ -2199,12 +2199,12 @@ QUtil::pdf_doc_to_utf8(std::string const& val) for (unsigned int i = 0; i < len; ++i) { unsigned char ch = static_cast(val.at(i)); - unsigned short val = ch; + unsigned short ch_short = ch; if ((ch >= 128) && (ch <= 160)) { - val = pdf_doc_to_unicode[ch - 128]; + ch_short = pdf_doc_to_unicode[ch - 128]; } - result += QUtil::toUTF8(val); + result += QUtil::toUTF8(ch_short); } return result; } -- cgit v1.2.3-70-g09d2