Commit ac9c1f0d560540fda821b2775a475c71b47cb3a0

Authored by Jay Berkenbilt
1 parent 42294570

Security: replace operator[] with at

For std::string and std::vector, replace operator[] with at.  This was
done using an automated process.  See README.hardening for details.
ChangeLog
1 1 2013-10-05 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * Replace operator[] in std::string and std::vector with "at" in
  4 + order to get bounds checking. This reduces the chances that
  5 + incorrect code will result in data exposure or buffer overruns.
  6 + See README.hardening for additional notes.
  7 +
3 8 * Use cryptographically secure random number generation when
4 9 available. See additional notes in README.
5 10  
... ...
README.hardening 0 → 100644
  1 +Avoiding operator[]
  2 +===================
  3 +
  4 +During a security review by Red Hat security team (specifically
  5 +Florian Weimer), it was discovered that qpdf used std::string and
  6 +std::vector's operator[], which has no bounds checking by design.
  7 +Instead, using those objects' at() method is preferable since it does
  8 +bounds checking. Florian has a tool that can detect all uses of these
  9 +methods and report them. I have a short perl script that
  10 +automatically corrects any such uses. The perl script is not intended
  11 +to be general, but it could be reasonably general. The only known
  12 +shortcut is that it might not work very well with some cases of nested
  13 +[]'s like a[b[c]] or with cases where there are line breaks inside the
  14 +brackets. For qpdf's coding style, it worked on all cases reported.
  15 +
  16 +To use this, obtain htcondor-analyzer, run it, and respond to the
  17 +report. Here's what I did.
  18 +
  19 +sudo aptitude install libclang-dev llvm llvm-dev clang
  20 +cd /tmp
  21 +git clone https://github.com/fweimer/htcondor-analyzer
  22 +# HEAD = 5fa06fc68a9b0677e9de162279185d58ba1e8477 at this writing
  23 +cd htcondor-analyzer
  24 +make
  25 +
  26 +in qpdf
  27 +
  28 +./autogen.sh
  29 +/tmp/htcondor-analyzer/create-db
  30 +CC=/tmp/htcondor-analyzer/cc CXX=/tmp/htcondor-analyzer/cxx ./configure --disable-shared --disable-werror
  31 +# to remove conftest.c
  32 +\rm htcondor-analyzer.sqlite
  33 +/tmp/htcondor-analyzer/create-db
  34 +
  35 +Repeat until no more errors:
  36 +
  37 +/tmp/fix-at.pl is shown below.
  38 +
  39 +make
  40 +/tmp/htcondor-analyzer/report | grep std:: | grep qpdf >| /tmp/r
  41 +perl /tmp/fix-at.pl /tmp/r
  42 +# move all *.new over the original file. patmv is my script. Can
  43 +# also use a for loop.
  44 +patmv -f s/.new// **/*.new
  45 +
  46 +---------- /tmp/fix-at.pl ----------
  47 +#!/usr/bin/env perl
  48 +require 5.008;
  49 +use warnings;
  50 +use strict;
  51 +use File::Basename;
  52 +
  53 +my $whoami = basename($0);
  54 +
  55 +my %to_fix = ();
  56 +while (<>)
  57 +{
  58 + chomp;
  59 + die unless m/^([^:]+):(\d+):(\d+):\s*(.*)$/;
  60 + my ($file, $line, $col, $message) = ($1, $2, $3, $4);
  61 + if ($message !~ m/operator\[\]/)
  62 + {
  63 + warn "skipping $_\n";
  64 + next;
  65 + }
  66 + push(@{$to_fix{$file}}, [$line, $col, $message]);
  67 +}
  68 +foreach my $file (sort keys %to_fix)
  69 +{
  70 + open(F, "<$file") or die;
  71 + my @lines = (<F>);
  72 + close(F);
  73 + my $last = "";
  74 + my @data = reverse sort { ($a->[0] <=> $b->[0]) || ($a->[1] <=> $b->[1]) } @{$to_fix{$file}};
  75 + foreach my $d (@data)
  76 + {
  77 + my ($line, $col) = @$d;
  78 + next if $last eq "$line:$col";
  79 + $last = "$line:$col";
  80 + die if $line-- < 1;
  81 + die if $col-- < 1;
  82 + print $lines[$line];
  83 + $lines[$line] =~ s/^(.{$col})([^\[]+)\[([^\]]+)\]/$1$2.at($3)/ or die "$file:$last\n";
  84 + print $lines[$line];
  85 + }
  86 + open(F, ">$file.new") or die;
  87 + foreach my $line (@lines)
  88 + {
  89 + print F $line;
  90 + }
  91 + close(F) or die;
  92 +}
  93 +--------------------
... ...
README.maintainer
... ... @@ -43,6 +43,9 @@ Release Reminders
43 43 casting policy in the manual, and ensure that integer types are
44 44 properly handled.
45 45  
  46 + * Remember to avoid using operator[] with std::string or
  47 + std::vector. See README.hardening for details.
  48 +
46 49 * Increment shared library version information as needed
47 50 (libqpdf/build.mk)
48 51  
... ...
examples/pdf-bookmarks.cc
... ... @@ -31,7 +31,7 @@ void print_lines(std::vector&lt;int&gt;&amp; numbers)
31 31 {
32 32 for (unsigned int i = 0; i < numbers.size() - 1; ++i)
33 33 {
34   - if (numbers[i])
  34 + if (numbers.at(i))
35 35 {
36 36 std::cout << "| ";
37 37 }
... ...
examples/pdf-mod-info.cc
... ... @@ -128,7 +128,7 @@ int main(int argc, char* argv[])
128 128 {
129 129 QTC::TC("examples", "pdf-mod-info -key");
130 130 cur_key = argv[i];
131   - if (! ((cur_key.length() > 0) && (cur_key[0] == '/')))
  131 + if (! ((cur_key.length() > 0) && (cur_key.at(0) == '/')))
132 132 {
133 133 cur_key = "/" + cur_key;
134 134 }
... ...
examples/pdf-parse-content.cc
... ... @@ -74,7 +74,7 @@ int main(int argc, char* argv[])
74 74 usage();
75 75 }
76 76  
77   - QPDFObjectHandle page = pages[pageno-1];
  77 + QPDFObjectHandle page = pages.at(pageno-1);
78 78 QPDFObjectHandle contents = page.getKey("/Contents");
79 79 ParserCallbacks cb;
80 80 QPDFObjectHandle::parseContentStream(contents, &cb);
... ...
libqpdf/Pl_LZWDecoder.cc
... ... @@ -109,7 +109,7 @@ Pl_LZWDecoder::getFirstChar(int code)
109 109 throw std::logic_error(
110 110 "Pl_LZWDecoder::getFirstChar: table overflow");
111 111 }
112   - Buffer& b = table[idx];
  112 + Buffer& b = table.at(idx);
113 113 result = b.getBuffer()[0];
114 114 }
115 115 else
... ... @@ -142,7 +142,7 @@ Pl_LZWDecoder::addToTable(unsigned char next)
142 142 throw std::logic_error(
143 143 "Pl_LZWDecoder::addToTable: table overflow");
144 144 }
145   - Buffer& b = table[idx];
  145 + Buffer& b = table.at(idx);
146 146 last_data = b.getBuffer();
147 147 last_size = b.getSize();
148 148 }
... ... @@ -238,7 +238,7 @@ Pl_LZWDecoder::handleCode(int code)
238 238 }
239 239 else
240 240 {
241   - Buffer& b = table[code - 258];
  241 + Buffer& b = table.at(code - 258);
242 242 getNext()->write(b.getBuffer(), b.getSize());
243 243 }
244 244 }
... ...
libqpdf/QPDF.cc
... ... @@ -531,7 +531,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
531 531 // For xref_table, these will always be small enough to be ints
532 532 qpdf_offset_t f1 = QUtil::string_to_ll(m2.getMatch(1).c_str());
533 533 int f2 = atoi(m2.getMatch(2).c_str());
534   - char type = m2.getMatch(3)[0];
  534 + char type = m2.getMatch(3).at(0);
535 535 if (type == 'f')
536 536 {
537 537 // Save deleted items until after we've checked the
... ... @@ -758,17 +758,17 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
758 758 long long num_entries = 0;
759 759 for (unsigned int i = 1; i < indx.size(); i += 2)
760 760 {
761   - if (indx[i] > max_num_entries - num_entries)
  761 + if (indx.at(i) > max_num_entries - num_entries)
762 762 {
763 763 throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(),
764 764 "xref stream", xref_offset,
765 765 "Cross-reference stream claims to contain"
766 766 " too many entries: " +
767   - QUtil::int_to_string(indx[i]) + " " +
  767 + QUtil::int_to_string(indx.at(i)) + " " +
768 768 QUtil::int_to_string(max_num_entries) + " " +
769 769 QUtil::int_to_string(num_entries));
770 770 }
771   - num_entries += indx[i];
  771 + num_entries += indx.at(i);
772 772 }
773 773  
774 774 // entry_size and num_entries have both been validated to ensure
... ... @@ -829,9 +829,9 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
829 829 // based on /Index. The generation number is 0 unless this is
830 830 // an uncompressed object record, in which case the generation
831 831 // number appears as the third field.
832   - int obj = indx[cur_chunk] + chunk_count;
  832 + int obj = indx.at(cur_chunk) + chunk_count;
833 833 ++chunk_count;
834   - if (chunk_count >= indx[cur_chunk + 1])
  834 + if (chunk_count >= indx.at(cur_chunk + 1))
835 835 {
836 836 cur_chunk += 2;
837 837 chunk_count = 0;
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -712,7 +712,7 @@ QPDFObjectHandle::parse(std::string const&amp; object_str,
712 712 size_t offset = input->tell();
713 713 while (offset < object_str.length())
714 714 {
715   - if (! isspace(object_str[offset]))
  715 + if (! isspace(object_str.at(offset)))
716 716 {
717 717 QTC::TC("qpdf", "QPDFObjectHandle trailing data in parse");
718 718 throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),
... ... @@ -966,8 +966,8 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
966 966 std::string const& value = token.getValue();
967 967 if ((value == "R") && (in_array || in_dictionary) &&
968 968 (olist.size() >= 2) &&
969   - (olist[olist.size() - 1].isInteger()) &&
970   - (olist[olist.size() - 2].isInteger()))
  969 + (olist.at(olist.size() - 1).isInteger()) &&
  970 + (olist.at(olist.size() - 2).isInteger()))
971 971 {
972 972 if (context == 0)
973 973 {
... ... @@ -979,8 +979,8 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
979 979 // Try to resolve indirect objects
980 980 object = newIndirect(
981 981 context,
982   - olist[olist.size() - 2].getIntValue(),
983   - olist[olist.size() - 1].getIntValue());
  982 + olist.at(olist.size() - 2).getIntValue(),
  983 + olist.at(olist.size() - 1).getIntValue());
984 984 olist.pop_back();
985 985 olist.pop_back();
986 986 }
... ... @@ -1067,8 +1067,8 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
1067 1067 }
1068 1068 for (unsigned int i = 0; i < olist.size(); i += 2)
1069 1069 {
1070   - QPDFObjectHandle key_obj = olist[i];
1071   - QPDFObjectHandle val = olist[i + 1];
  1070 + QPDFObjectHandle key_obj = olist.at(i);
  1071 + QPDFObjectHandle val = olist.at(i + 1);
1072 1072 if (! key_obj.isName())
1073 1073 {
1074 1074 throw QPDFExc(
... ...
libqpdf/QPDFTokenizer.cc
... ... @@ -61,7 +61,7 @@ QPDFTokenizer::resolveLiteral()
61 61 {
62 62 PCRE num_re("^[\\+\\-]?(?:\\.\\d+|\\d+(?:\\.\\d+)?)$");
63 63  
64   - if ((val.length() > 0) && (val[0] == '/'))
  64 + if ((val.length() > 0) && (val.at(0) == '/'))
65 65 {
66 66 type = tt_name;
67 67 // Deal with # in name token. Note: '/' by itself is a
... ... @@ -397,8 +397,8 @@ QPDFTokenizer::presentCharacter(char ch)
397 397 std::string nval;
398 398 for (unsigned int i = 0; i < val.length(); i += 2)
399 399 {
400   - num[0] = val[i];
401   - num[1] = val[i+1];
  400 + num[0] = val.at(i);
  401 + num[1] = val.at(i+1);
402 402 char nch = static_cast<char>(strtol(num, 0, 16));
403 403 nval += nch;
404 404 }
... ...
libqpdf/QPDFWriter.cc
... ... @@ -1569,7 +1569,7 @@ QPDFWriter::writeObjectStreamOffsets(std::vector&lt;qpdf_offset_t&gt;&amp; offsets,
1569 1569 }
1570 1570 writeString(QUtil::int_to_string(i + first_obj));
1571 1571 writeString(" ");
1572   - writeString(QUtil::int_to_string(offsets[i]));
  1572 + writeString(QUtil::int_to_string(offsets.at(i)));
1573 1573 }
1574 1574 writeString("\n");
1575 1575 }
... ... @@ -1603,7 +1603,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
1603 1603 {
1604 1604 // Adjust offsets to skip over comment before first object
1605 1605  
1606   - first = offsets[0];
  1606 + first = offsets.at(0);
1607 1607 for (std::vector<qpdf_offset_t>::iterator iter = offsets.begin();
1608 1608 iter != offsets.end(); ++iter)
1609 1609 {
... ... @@ -2745,7 +2745,7 @@ QPDFWriter::writeLinearized()
2745 2745 if (pass == 2)
2746 2746 {
2747 2747 std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
2748   - int first_page_object = obj_renumber[pages[0].getObjGen()];
  2748 + int first_page_object = obj_renumber[pages.at(0).getObjGen()];
2749 2749 int npages = pages.size();
2750 2750  
2751 2751 writeString(" /Linearized 1 /L ");
... ...
libqpdf/QPDF_Array.cc
... ... @@ -60,7 +60,7 @@ QPDF_Array::getItem(int n) const
60 60 throw std::logic_error(
61 61 "INTERNAL ERROR: bounds error accessing QPDF_Array element");
62 62 }
63   - return this->items[n];
  63 + return this->items.at(n);
64 64 }
65 65  
66 66 std::vector<QPDFObjectHandle> const&
... ... @@ -74,7 +74,7 @@ QPDF_Array::setItem(int n, QPDFObjectHandle const&amp; oh)
74 74 {
75 75 // Call getItem for bounds checking
76 76 (void) getItem(n);
77   - this->items[n] = oh;
  77 + this->items.at(n) = oh;
78 78 }
79 79  
80 80 void
... ...
libqpdf/QPDF_Name.cc
... ... @@ -21,10 +21,10 @@ QPDF_Name::normalizeName(std::string const&amp; name)
21 21 return name;
22 22 }
23 23 std::string result;
24   - result += name[0];
  24 + result += name.at(0);
25 25 for (unsigned int i = 1; i < name.length(); ++i)
26 26 {
27   - char ch = name[i];
  27 + char ch = name.at(i);
28 28 // Don't use locale/ctype here; follow PDF spec guidelines.
29 29 if (strchr("#()<>[]{}/%", ch) || (ch < 33) || (ch > 126))
30 30 {
... ...
libqpdf/QPDF_Stream.cc
... ... @@ -310,7 +310,7 @@ QPDF_Stream::filterable(std::vector&lt;std::string&gt;&amp; filters,
310 310  
311 311 for (unsigned int i = 0; i < filters.size(); ++i)
312 312 {
313   - QPDFObjectHandle decode_item = decode_parms[i];
  313 + QPDFObjectHandle decode_item = decode_parms.at(i);
314 314 if (decode_item.isNull())
315 315 {
316 316 // okay
... ... @@ -318,7 +318,7 @@ QPDF_Stream::filterable(std::vector&lt;std::string&gt;&amp; filters,
318 318 else if (decode_item.isDictionary())
319 319 {
320 320 if (! understandDecodeParams(
321   - filters[i], decode_item,
  321 + filters.at(i), decode_item,
322 322 predictor, columns, early_code_change))
323 323 {
324 324 filterable = false;
... ...
libqpdf/QPDF_String.cc
... ... @@ -55,7 +55,7 @@ QPDF_String::unparse(bool force_binary)
55 55 int consecutive_printable = 0;
56 56 for (unsigned int i = 0; i < this->val.length(); ++i)
57 57 {
58   - char ch = this->val[i];
  58 + char ch = this->val.at(i);
59 59 // Note: do not use locale to determine printability. The
60 60 // PDF specification accepts arbitrary binary data. Some
61 61 // locales imply multibyte characters. We'll consider
... ... @@ -97,7 +97,7 @@ QPDF_String::unparse(bool force_binary)
97 97 result += "(";
98 98 for (unsigned int i = 0; i < this->val.length(); ++i)
99 99 {
100   - char ch = this->val[i];
  100 + char ch = this->val.at(i);
101 101 switch (ch)
102 102 {
103 103 case '\n':
... ... @@ -135,7 +135,7 @@ QPDF_String::unparse(bool force_binary)
135 135 default:
136 136 if (is_iso_latin1_printable(ch))
137 137 {
138   - result += this->val[i];
  138 + result += this->val.at(i);
139 139 }
140 140 else
141 141 {
... ... @@ -164,7 +164,7 @@ QPDF_String::getUTF8Val() const
164 164 std::string result;
165 165 size_t len = this->val.length();
166 166 if ((len >= 2) && (len % 2 == 0) &&
167   - (this->val[0] == '\xfe') && (this->val[1] == '\xff'))
  167 + (this->val.at(0) == '\xfe') && (this->val.at(1) == '\xff'))
168 168 {
169 169 // This is a Unicode string using big-endian UTF-16. This
170 170 // code uses unsigned long and unsigned short to hold
... ... @@ -181,8 +181,8 @@ QPDF_String::getUTF8Val() const
181 181 // discarded, and a low codepoint not preceded by a high
182 182 // codepoint will just get its low 10 bits output.
183 183 unsigned short bits =
184   - (static_cast<unsigned char>(this->val[i]) << 8) +
185   - static_cast<unsigned char>(this->val[i+1]);
  184 + (static_cast<unsigned char>(this->val.at(i)) << 8) +
  185 + static_cast<unsigned char>(this->val.at(i+1));
186 186 if ((bits & 0xFC00) == 0xD800)
187 187 {
188 188 codepoint = 0x10000 + ((bits & 0x3FF) << 10);
... ... @@ -209,7 +209,7 @@ QPDF_String::getUTF8Val() const
209 209 {
210 210 for (unsigned int i = 0; i < len; ++i)
211 211 {
212   - result += QUtil::toUTF8(static_cast<unsigned char>(this->val[i]));
  212 + result += QUtil::toUTF8(static_cast<unsigned char>(this->val.at(i)));
213 213 }
214 214 }
215 215 return result;
... ...
libqpdf/QPDF_encryption.cc
... ... @@ -312,7 +312,7 @@ hash_V5(std::string const&amp; password,
312 312 int E_mod_3 = 0;
313 313 for (unsigned int i = 0; i < 16; ++i)
314 314 {
315   - E_mod_3 += static_cast<unsigned char>(E[i]);
  315 + E_mod_3 += static_cast<unsigned char>(E.at(i));
316 316 }
317 317 E_mod_3 %= 3;
318 318 int next_hash = ((E_mod_3 == 0) ? 256 :
... ...
libqpdf/QPDF_linearization.cc
... ... @@ -33,7 +33,7 @@ load_vector_int(BitStream&amp; bit_stream, int nitems, std::vector&lt;T&gt;&amp; vec,
33 33 {
34 34 vec.push_back(T());
35 35 }
36   - vec[i].*field = bit_stream.getBits(bits_wanted);
  36 + vec.at(i).*field = bit_stream.getBits(bits_wanted);
37 37 }
38 38 if (static_cast<int>(vec.size()) != nitems)
39 39 {
... ... @@ -54,9 +54,9 @@ load_vector_vector(BitStream&amp; bit_stream,
54 54 // into the vec2 vector field of the ith item of vec1.
55 55 for (int i1 = 0; i1 < nitems1; ++i1)
56 56 {
57   - for (int i2 = 0; i2 < vec1[i1].*nitems2; ++i2)
  57 + for (int i2 = 0; i2 < vec1.at(i1).*nitems2; ++i2)
58 58 {
59   - (vec1[i1].*vec2).push_back(bit_stream.getBits(bits_wanted));
  59 + (vec1.at(i1).*vec2).push_back(bit_stream.getBits(bits_wanted));
60 60 }
61 61 }
62 62 bit_stream.skipToNextByte();
... ... @@ -237,8 +237,8 @@ QPDF::readLinearizationData()
237 237 }
238 238  
239 239 // H: hint table offset/length for primary and overflow hint tables
240   - int H0_offset = H_items[0];
241   - int H0_length = H_items[1];
  240 + int H0_offset = H_items.at(0);
  241 + int H0_length = H_items.at(1);
242 242 int H1_offset = 0;
243 243 int H1_length = 0;
244 244 if (H_items.size() == 4)
... ... @@ -246,8 +246,8 @@ QPDF::readLinearizationData()
246 246 // Acrobat doesn't read or write these (as PDF 1.4), so we
247 247 // don't have a way to generate a test case.
248 248 // QTC::TC("qpdf", "QPDF overflow hint table");
249   - H1_offset = H_items[2];
250   - H1_length = H_items[3];
  249 + H1_offset = H_items.at(2);
  250 + H1_length = H_items.at(3);
251 251 }
252 252  
253 253 // P: first page number
... ... @@ -470,7 +470,7 @@ QPDF::readHSharedObject(BitStream h)
470 470 1, &HSharedObjectEntry::signature_present);
471 471 for (int i = 0; i < nitems; ++i)
472 472 {
473   - if (entries[i].signature_present)
  473 + if (entries.at(i).signature_present)
474 474 {
475 475 // Skip 128-bit MD5 hash. These are not supported by
476 476 // acrobat, so they should probably never be there. We
... ... @@ -512,7 +512,7 @@ QPDF::checkLinearizationInternal()
512 512  
513 513 // O: object number of first page
514 514 std::vector<QPDFObjectHandle> const& pages = getAllPages();
515   - if (p.first_page_object != pages[0].getObjectID())
  515 + if (p.first_page_object != pages.at(0).getObjectID())
516 516 {
517 517 QTC::TC("qpdf", "QPDF err /O mismatch");
518 518 errors.push_back("first page object (/O) mismatch");
... ... @@ -528,7 +528,7 @@ QPDF::checkLinearizationInternal()
528 528  
529 529 for (int i = 0; i < npages; ++i)
530 530 {
531   - QPDFObjectHandle const& page = pages[i];
  531 + QPDFObjectHandle const& page = pages.at(i);
532 532 QPDFObjGen og(page.getObjGen());
533 533 if (this->xref_table[og].getType() == 2)
534 534 {
... ... @@ -776,7 +776,7 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors,
776 776 unsigned int npages = pages.size();
777 777 int table_offset = adjusted_offset(
778 778 this->page_offset_hints.first_page_offset);
779   - QPDFObjGen first_page_og(pages[0].getObjGen());
  779 + QPDFObjGen first_page_og(pages.at(0).getObjGen());
780 780 assert(this->xref_table.count(first_page_og) > 0);
781 781 int offset = getLinearizationOffset(first_page_og);
782 782 if (table_offset != offset)
... ... @@ -786,13 +786,13 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors,
786 786  
787 787 for (unsigned int pageno = 0; pageno < npages; ++pageno)
788 788 {
789   - QPDFObjGen page_og(pages[pageno].getObjGen());
  789 + QPDFObjGen page_og(pages.at(pageno).getObjGen());
790 790 int first_object = page_og.getObj();
791 791 assert(this->xref_table.count(page_og) > 0);
792 792 offset = getLinearizationOffset(page_og);
793 793  
794   - HPageOffsetEntry& he = this->page_offset_hints.entries[pageno];
795   - CHPageOffsetEntry& ce = this->c_page_offset_data.entries[pageno];
  794 + HPageOffsetEntry& he = this->page_offset_hints.entries.at(pageno);
  795 + CHPageOffsetEntry& ce = this->c_page_offset_data.entries.at(pageno);
796 796 int h_nobjects = he.delta_nobjects +
797 797 this->page_offset_hints.min_nobjects;
798 798 if (h_nobjects != ce.nobjects)
... ... @@ -837,7 +837,7 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors,
837 837  
838 838 for (int i = 0; i < he.nshared_objects; ++i)
839 839 {
840   - int idx = he.shared_identifiers[i];
  840 + int idx = he.shared_identifiers.at(i);
841 841 if (shared_idx_to_obj.count(idx) == 0)
842 842 {
843 843 throw std::logic_error(
... ... @@ -849,13 +849,13 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors,
849 849  
850 850 for (int i = 0; i < ce.nshared_objects; ++i)
851 851 {
852   - int idx = ce.shared_identifiers[i];
  852 + int idx = ce.shared_identifiers.at(i);
853 853 if (idx >= this->c_shared_object_data.nshared_total)
854 854 {
855 855 throw std::logic_error(
856 856 "index out of bounds for shared object hint table");
857 857 }
858   - int obj = this->c_shared_object_data.entries[idx].object;
  858 + int obj = this->c_shared_object_data.entries.at(idx).object;
859 859 computed_shared.insert(obj);
860 860 }
861 861  
... ... @@ -923,7 +923,7 @@ QPDF::checkHSharedObject(std::list&lt;std::string&gt;&amp; errors,
923 923 // The first nshared_first_page objects are consecutive
924 924 // objects starting with the first page object. The rest are
925 925 // consecutive starting from the first_shared_obj object.
926   - int cur_object = pages[0].getObjectID();
  926 + int cur_object = pages.at(0).getObjectID();
927 927 for (int i = 0; i < so.nshared_total; ++i)
928 928 {
929 929 if (i == so.nshared_first_page)
... ... @@ -937,7 +937,7 @@ QPDF::checkHSharedObject(std::list&lt;std::string&gt;&amp; errors,
937 937 }
938 938 else
939 939 {
940   - int obj = this->part8[0].getObjectID();
  940 + int obj = this->part8.at(0).getObjectID();
941 941 if (obj != so.first_shared_obj)
942 942 {
943 943 errors.push_back(
... ... @@ -965,7 +965,7 @@ QPDF::checkHSharedObject(std::list&lt;std::string&gt;&amp; errors,
965 965 }
966 966  
967 967 idx_to_obj[i] = cur_object;
968   - HSharedObjectEntry& se = so.entries[i];
  968 + HSharedObjectEntry& se = so.entries.at(i);
969 969 int nobjects = se.nobjects_minus_one + 1;
970 970 int length = lengthNextN(cur_object, nobjects, errors);
971 971 int h_length = so.min_group_length + se.delta_group_length;
... ... @@ -1146,7 +1146,7 @@ QPDF::dumpHPageOffset()
1146 1146  
1147 1147 for (int i1 = 0; i1 < this->linp.npages; ++i1)
1148 1148 {
1149   - HPageOffsetEntry& pe = t.entries[i1];
  1149 + HPageOffsetEntry& pe = t.entries.at(i1);
1150 1150 *out_stream
1151 1151 << "Page " << i1 << ":" << std::endl
1152 1152 << " nobjects: " << pe.delta_nobjects + t.min_nobjects
... ... @@ -1162,9 +1162,9 @@ QPDF::dumpHPageOffset()
1162 1162 for (int i2 = 0; i2 < pe.nshared_objects; ++i2)
1163 1163 {
1164 1164 *out_stream << " identifier " << i2 << ": "
1165   - << pe.shared_identifiers[i2] << std::endl;
  1165 + << pe.shared_identifiers.at(i2) << std::endl;
1166 1166 *out_stream << " numerator " << i2 << ": "
1167   - << pe.shared_numerators[i2] << std::endl;
  1167 + << pe.shared_numerators.at(i2) << std::endl;
1168 1168 }
1169 1169 }
1170 1170 }
... ... @@ -1191,7 +1191,7 @@ QPDF::dumpHSharedObject()
1191 1191  
1192 1192 for (int i = 0; i < t.nshared_total; ++i)
1193 1193 {
1194   - HSharedObjectEntry& se = t.entries[i];
  1194 + HSharedObjectEntry& se = t.entries.at(i);
1195 1195 *out_stream << "Shared Object " << i << ":" << std::endl;
1196 1196 *out_stream << " group length: "
1197 1197 << se.delta_group_length + t.min_group_length << std::endl;
... ... @@ -1522,7 +1522,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1522 1522 // will do the same.
1523 1523  
1524 1524 // First, place the actual first page object itself.
1525   - QPDFObjGen first_page_og(pages[0].getObjGen());
  1525 + QPDFObjGen first_page_og(pages.at(0).getObjGen());
1526 1526 if (! lc_first_page_private.count(first_page_og))
1527 1527 {
1528 1528 throw std::logic_error(
... ... @@ -1530,8 +1530,8 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1530 1530 "object not in lc_first_page_private");
1531 1531 }
1532 1532 lc_first_page_private.erase(first_page_og);
1533   - this->c_linp.first_page_object = pages[0].getObjectID();
1534   - this->part6.push_back(pages[0]);
  1533 + this->c_linp.first_page_object = pages.at(0).getObjectID();
  1534 + this->part6.push_back(pages.at(0));
1535 1535  
1536 1536 // The PDF spec "recommends" an order for the rest of the objects,
1537 1537 // but we are going to disregard it except to the extent that it
... ... @@ -1562,7 +1562,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1562 1562 // in garbage values for all the shared object identifiers on the
1563 1563 // first page.
1564 1564  
1565   - this->c_page_offset_data.entries[0].nobjects = this->part6.size();
  1565 + this->c_page_offset_data.entries.at(0).nobjects = this->part6.size();
1566 1566  
1567 1567 // Part 7: other pages' private objects
1568 1568  
... ... @@ -1571,7 +1571,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1571 1571 {
1572 1572 // Place this page's page object
1573 1573  
1574   - QPDFObjGen page_og(pages[i].getObjGen());
  1574 + QPDFObjGen page_og(pages.at(i).getObjGen());
1575 1575 if (! lc_other_page_private.count(page_og))
1576 1576 {
1577 1577 throw std::logic_error(
... ... @@ -1580,12 +1580,12 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1580 1580 QUtil::int_to_string(i) + " not in lc_other_page_private");
1581 1581 }
1582 1582 lc_other_page_private.erase(page_og);
1583   - this->part7.push_back(pages[i]);
  1583 + this->part7.push_back(pages.at(i));
1584 1584  
1585 1585 // Place all non-shared objects referenced by this page,
1586 1586 // updating the page object count for the hint table.
1587 1587  
1588   - this->c_page_offset_data.entries[i].nobjects = 1;
  1588 + this->c_page_offset_data.entries.at(i).nobjects = 1;
1589 1589  
1590 1590 ObjUser ou(ObjUser::ou_page, i);
1591 1591 assert(this->obj_user_to_objects.count(ou) > 0);
... ... @@ -1598,7 +1598,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1598 1598 {
1599 1599 lc_other_page_private.erase(og);
1600 1600 this->part7.push_back(objGenToIndirect(og));
1601   - ++this->c_page_offset_data.entries[i].nobjects;
  1601 + ++this->c_page_offset_data.entries.at(i).nobjects;
1602 1602 }
1603 1603 }
1604 1604 }
... ... @@ -1649,7 +1649,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1649 1649 // thumbnail hint tables.
1650 1650 for (unsigned int i = 0; i < npages; ++i)
1651 1651 {
1652   - QPDFObjectHandle thumb = pages[i].getKey("/Thumb");
  1652 + QPDFObjectHandle thumb = pages.at(i).getKey("/Thumb");
1653 1653 thumb = getUncompressedObject(thumb, object_stream_data);
1654 1654 if (! thumb.isNull())
1655 1655 {
... ... @@ -1758,7 +1758,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1758 1758 if (! this->part8.empty())
1759 1759 {
1760 1760 this->c_shared_object_data.first_shared_obj =
1761   - this->part8[0].getObjectID();
  1761 + this->part8.at(0).getObjectID();
1762 1762 for (std::vector<QPDFObjectHandle>::iterator iter =
1763 1763 this->part8.begin();
1764 1764 iter != this->part8.end(); ++iter)
... ... @@ -1781,7 +1781,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1781 1781  
1782 1782 for (unsigned int i = 1; i < npages; ++i)
1783 1783 {
1784   - CHPageOffsetEntry& pe = this->c_page_offset_data.entries[i];
  1784 + CHPageOffsetEntry& pe = this->c_page_offset_data.entries.at(i);
1785 1785 ObjUser ou(ObjUser::ou_page, i);
1786 1786 assert(this->obj_user_to_objects.count(ou) > 0);
1787 1787 std::set<QPDFObjGen> const& ogs = this->obj_user_to_objects[ou];
... ... @@ -1892,12 +1892,12 @@ QPDF::calculateHPageOffset(
1892 1892 // Calculate minimum and maximum values for number of objects per
1893 1893 // page and page length.
1894 1894  
1895   - int min_nobjects = cphe[0].nobjects;
  1895 + int min_nobjects = cphe.at(0).nobjects;
1896 1896 int max_nobjects = min_nobjects;
1897 1897 int min_length = outputLengthNextN(
1898   - pages[0].getObjectID(), min_nobjects, lengths, obj_renumber);
  1898 + pages.at(0).getObjectID(), min_nobjects, lengths, obj_renumber);
1899 1899 int max_length = min_length;
1900   - int max_shared = cphe[0].nshared_objects;
  1900 + int max_shared = cphe.at(0).nshared_objects;
1901 1901  
1902 1902 HPageOffset& ph = this->page_offset_hints;
1903 1903 std::vector<HPageOffsetEntry>& phe = ph.entries;
... ... @@ -1912,10 +1912,10 @@ QPDF::calculateHPageOffset(
1912 1912 // Repeat calculations for page 0 so we can assign to phe[i]
1913 1913 // without duplicating those assignments.
1914 1914  
1915   - int nobjects = cphe[i].nobjects;
  1915 + int nobjects = cphe.at(i).nobjects;
1916 1916 int length = outputLengthNextN(
1917   - pages[i].getObjectID(), nobjects, lengths, obj_renumber);
1918   - int nshared = cphe[i].nshared_objects;
  1917 + pages.at(i).getObjectID(), nobjects, lengths, obj_renumber);
  1918 + int nshared = cphe.at(i).nshared_objects;
1919 1919  
1920 1920 min_nobjects = std::min(min_nobjects, nobjects);
1921 1921 max_nobjects = std::max(max_nobjects, nobjects);
... ... @@ -1923,13 +1923,13 @@ QPDF::calculateHPageOffset(
1923 1923 max_length = std::max(max_length, length);
1924 1924 max_shared = std::max(max_shared, nshared);
1925 1925  
1926   - phe[i].delta_nobjects = nobjects;
1927   - phe[i].delta_page_length = length;
1928   - phe[i].nshared_objects = nshared;
  1926 + phe.at(i).delta_nobjects = nobjects;
  1927 + phe.at(i).delta_page_length = length;
  1928 + phe.at(i).nshared_objects = nshared;
1929 1929 }
1930 1930  
1931 1931 ph.min_nobjects = min_nobjects;
1932   - int in_page0_id = pages[0].getObjectID();
  1932 + int in_page0_id = pages.at(0).getObjectID();
1933 1933 int out_page0_id = (*(obj_renumber.find(in_page0_id))).second;
1934 1934 ph.first_page_offset = (*(xref.find(out_page0_id))).second.getOffset();
1935 1935 ph.nbits_delta_nobjects = nbits(max_nobjects - min_nobjects);
... ... @@ -1951,17 +1951,17 @@ QPDF::calculateHPageOffset(
1951 1951 for (unsigned int i = 0; i < npages; ++i)
1952 1952 {
1953 1953 // Adjust delta entries
1954   - assert(phe[i].delta_nobjects >= min_nobjects);
1955   - assert(phe[i].delta_page_length >= min_length);
1956   - phe[i].delta_nobjects -= min_nobjects;
1957   - phe[i].delta_page_length -= min_length;
1958   - phe[i].delta_content_length = phe[i].delta_page_length;
  1954 + assert(phe.at(i).delta_nobjects >= min_nobjects);
  1955 + assert(phe.at(i).delta_page_length >= min_length);
  1956 + phe.at(i).delta_nobjects -= min_nobjects;
  1957 + phe.at(i).delta_page_length -= min_length;
  1958 + phe.at(i).delta_content_length = phe.at(i).delta_page_length;
1959 1959  
1960   - for (int j = 0; j < cphe[i].nshared_objects; ++j)
  1960 + for (int j = 0; j < cphe.at(i).nshared_objects; ++j)
1961 1961 {
1962   - phe[i].shared_identifiers.push_back(
1963   - cphe[i].shared_identifiers[j]);
1964   - phe[i].shared_numerators.push_back(0);
  1962 + phe.at(i).shared_identifiers.push_back(
  1963 + cphe.at(i).shared_identifiers.at(j));
  1964 + phe.at(i).shared_numerators.push_back(0);
1965 1965 }
1966 1966 }
1967 1967 }
... ... @@ -1979,18 +1979,18 @@ QPDF::calculateHSharedObject(
1979 1979 soe.clear();
1980 1980  
1981 1981 int min_length = outputLengthNextN(
1982   - csoe[0].object, 1, lengths, obj_renumber);
  1982 + csoe.at(0).object, 1, lengths, obj_renumber);
1983 1983 int max_length = min_length;
1984 1984  
1985 1985 for (int i = 0; i < cso.nshared_total; ++i)
1986 1986 {
1987 1987 // Assign absolute numbers to deltas; adjust later
1988 1988 int length = outputLengthNextN(
1989   - csoe[i].object, 1, lengths, obj_renumber);
  1989 + csoe.at(i).object, 1, lengths, obj_renumber);
1990 1990 min_length = std::min(min_length, length);
1991 1991 max_length = std::max(max_length, length);
1992 1992 soe.push_back(HSharedObjectEntry());
1993   - soe[i].delta_group_length = length;
  1993 + soe.at(i).delta_group_length = length;
1994 1994 }
1995 1995 if (soe.size() != static_cast<size_t>(cso.nshared_total))
1996 1996 {
... ... @@ -2012,8 +2012,8 @@ QPDF::calculateHSharedObject(
2012 2012 for (int i = 0; i < cso.nshared_total; ++i)
2013 2013 {
2014 2014 // Adjust deltas
2015   - assert(soe[i].delta_group_length >= min_length);
2016   - soe[i].delta_group_length -= min_length;
  2015 + assert(soe.at(i).delta_group_length >= min_length);
  2016 + soe.at(i).delta_group_length -= min_length;
2017 2017 }
2018 2018 }
2019 2019  
... ... @@ -2051,7 +2051,7 @@ write_vector_int(BitWriter&amp; w, int nitems, std::vector&lt;T&gt;&amp; vec,
2051 2051  
2052 2052 for (int i = 0; i < nitems; ++i)
2053 2053 {
2054   - w.writeBits(vec[i].*field, bits);
  2054 + w.writeBits(vec.at(i).*field, bits);
2055 2055 }
2056 2056 // The PDF spec says that each hint table starts at a byte
2057 2057 // boundary. Each "row" actually must start on a byte boundary.
... ... @@ -2068,9 +2068,9 @@ write_vector_vector(BitWriter&amp; w,
2068 2068 // from the vec2 vector field of the ith item of vec1.
2069 2069 for (int i1 = 0; i1 < nitems1; ++i1)
2070 2070 {
2071   - for (int i2 = 0; i2 < vec1[i1].*nitems2; ++i2)
  2071 + for (int i2 = 0; i2 < vec1.at(i1).*nitems2; ++i2)
2072 2072 {
2073   - w.writeBits((vec1[i1].*vec2)[i2], bits);
  2073 + w.writeBits((vec1.at(i1).*vec2).at(i2), bits);
2074 2074 }
2075 2075 }
2076 2076 w.flush();
... ... @@ -2151,7 +2151,7 @@ QPDF::writeHSharedObject(BitWriter&amp; w)
2151 2151 for (int i = 0; i < nitems; ++i)
2152 2152 {
2153 2153 // If signature were present, we'd have to write a 128-bit hash.
2154   - assert(entries[i].signature_present == 0);
  2154 + assert(entries.at(i).signature_present == 0);
2155 2155 }
2156 2156 write_vector_int(w, nitems, entries,
2157 2157 t.nbits_nobjects,
... ...
libqpdf/QPDF_optimization.cc
... ... @@ -91,7 +91,7 @@ QPDF::optimize(std::map&lt;int, int&gt; const&amp; object_stream_data,
91 91 for (int pageno = 0; pageno < n; ++pageno)
92 92 {
93 93 updateObjectMaps(ObjUser(ObjUser::ou_page, pageno),
94   - this->all_pages[pageno]);
  94 + this->all_pages.at(pageno));
95 95 }
96 96  
97 97 // Traverse document-level items
... ...
libqpdf/QPDF_pages.cc
... ... @@ -114,8 +114,8 @@ QPDF::flattenPagesTree()
114 114 for (int pos = 0; pos < len; ++pos)
115 115 {
116 116 // populate pageobj_to_pages_pos and fix parent pointer
117   - insertPageobjToPage(this->all_pages[pos], pos, true);
118   - this->all_pages[pos].replaceKey("/Parent", pages);
  117 + insertPageobjToPage(this->all_pages.at(pos), pos, true);
  118 + this->all_pages.at(pos).replaceKey("/Parent", pages);
119 119 }
120 120  
121 121 pages.replaceKey("/Kids", QPDFObjectHandle::newArray(this->all_pages));
... ... @@ -194,7 +194,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
194 194 assert(this->all_pages.size() == static_cast<size_t>(npages));
195 195 for (int i = pos + 1; i < npages; ++i)
196 196 {
197   - insertPageobjToPage(this->all_pages[i], i, false);
  197 + insertPageobjToPage(this->all_pages.at(i), i, false);
198 198 }
199 199 insertPageobjToPage(newpage, pos, true);
200 200 assert(this->pageobj_to_pages_pos.size() == static_cast<size_t>(npages));
... ... @@ -221,7 +221,7 @@ QPDF::removePage(QPDFObjectHandle page)
221 221 assert(this->pageobj_to_pages_pos.size() == static_cast<size_t>(npages));
222 222 for (int i = pos; i < npages; ++i)
223 223 {
224   - insertPageobjToPage(this->all_pages[i], i, false);
  224 + insertPageobjToPage(this->all_pages.at(i), i, false);
225 225 }
226 226 }
227 227  
... ...
libqpdf/QUtil.cc
... ... @@ -201,7 +201,7 @@ QUtil::hex_encode(std::string const&amp; input)
201 201 for (unsigned int i = 0; i < input.length(); ++i)
202 202 {
203 203 result += QUtil::int_to_string_base(
204   - static_cast<int>(static_cast<unsigned char>(input[i])), 16, 2);
  204 + static_cast<int>(static_cast<unsigned char>(input.at(i))), 16, 2);
205 205 }
206 206 return result;
207 207 }
... ...
qpdf/qpdf.cc
... ... @@ -441,7 +441,7 @@ static std::vector&lt;int&gt; parse_numrange(char const* range, int max,
441 441 p = 0;
442 442 for (size_t i = 0; i < work.size(); i += 2)
443 443 {
444   - int num = work[i];
  444 + int num = work.at(i);
445 445 // max == 0 means we don't know the max and are just
446 446 // testing for valid syntax.
447 447 if ((max > 0) && ((num < 1) || (num > max)))
... ... @@ -451,11 +451,11 @@ static std::vector&lt;int&gt; parse_numrange(char const* range, int max,
451 451 }
452 452 if (i == 0)
453 453 {
454   - result.push_back(work[i]);
  454 + result.push_back(work.at(i));
455 455 }
456 456 else
457 457 {
458   - int separator = work[i-1];
  458 + int separator = work.at(i-1);
459 459 if (separator == comma)
460 460 {
461 461 result.push_back(num);
... ... @@ -1664,7 +1664,7 @@ int main(int argc, char* argv[])
1664 1664 // Pages are specified from 1 but numbered
1665 1665 // from 0 in the vector
1666 1666 int pageno = *pageno_iter - 1;
1667   - pdf.addPage(page_data.orig_pages[pageno], false);
  1667 + pdf.addPage(page_data.orig_pages.at(pageno), false);
1668 1668 if (page_data.qpdf == &pdf)
1669 1669 {
1670 1670 // This is a page from the original file.
... ... @@ -1683,7 +1683,7 @@ int main(int argc, char* argv[])
1683 1683 {
1684 1684 if (selected_from_orig.count(pageno) == 0)
1685 1685 {
1686   - pdf.replaceObject(orig_pages[pageno].getObjGen(),
  1686 + pdf.replaceObject(orig_pages.at(pageno).getObjGen(),
1687 1687 QPDFObjectHandle::newNull());
1688 1688 }
1689 1689 }
... ...
qpdf/test_driver.cc
... ... @@ -603,10 +603,10 @@ void runtest(int n, char const* filename1, char const* arg2)
603 603 else if (n == 10)
604 604 {
605 605 std::vector<QPDFObjectHandle> pages = pdf.getAllPages();
606   - pages[0].addPageContents(
  606 + pages.at(0).addPageContents(
607 607 QPDFObjectHandle::newStream(
608 608 &pdf, "BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n"), true);
609   - pages[0].addPageContents(
  609 + pages.at(0).addPageContents(
610 610 QPDFObjectHandle::newStream(
611 611 &pdf, "BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n"), false);
612 612  
... ... @@ -659,7 +659,7 @@ void runtest(int n, char const* filename1, char const* arg2)
659 659 " not called 4-page file");
660 660 }
661 661 // Swap pages 2 and 3
662   - pdf.swapObjects(pages[1].getObjGen(), pages[2].getObjGen());
  662 + pdf.swapObjects(pages.at(1).getObjGen(), pages.at(2).getObjGen());
663 663 // Replace object and swap objects
664 664 QPDFObjectHandle trailer = pdf.getTrailer();
665 665 QPDFObjectHandle qdict = trailer.getKey("/QDict");
... ... @@ -700,7 +700,7 @@ void runtest(int n, char const* filename1, char const* arg2)
700 700 std::map<std::string, QPDFObjectHandle> dict_items =
701 701 qarray.getDictAsMap();
702 702 if ((array_elements.size() == 1) &&
703   - (array_elements[0].getName() == "/Array") &&
  703 + (array_elements.at(0).getName() == "/Array") &&
704 704 (dict_items.size() == 1) &&
705 705 (dict_items["/NewDict"].getIntValue() == 2))
706 706 {
... ... @@ -738,12 +738,12 @@ void runtest(int n, char const* filename1, char const* arg2)
738 738 assert(pages.size() == 9);
739 739 pdf.removePage(*pages.begin()); // original page 0
740 740 assert(pages.size() == 8);
741   - checkPageContents(pages[4], "Original page 5");
742   - pdf.removePage(pages[4]); // original page 5
  741 + checkPageContents(pages.at(4), "Original page 5");
  742 + pdf.removePage(pages.at(4)); // original page 5
743 743 assert(pages.size() == 7);
744   - checkPageContents(pages[4], "Original page 6");
745   - checkPageContents(pages[0], "Original page 1");
746   - checkPageContents(pages[6], "Original page 8");
  744 + checkPageContents(pages.at(4), "Original page 6");
  745 + checkPageContents(pages.at(0), "Original page 1");
  746 + checkPageContents(pages.at(6), "Original page 8");
747 747  
748 748 // Insert pages
749 749  
... ... @@ -760,7 +760,7 @@ void runtest(int n, char const* filename1, char const* arg2)
760 760 // dictionary and modify it. Using the results of
761 761 // getDictAsMap to create a new dictionary effectively creates
762 762 // a shallow copy.
763   - QPDFObjectHandle page_template = pages[0];
  763 + QPDFObjectHandle page_template = pages.at(0);
764 764 std::vector<QPDFObjectHandle> new_pages;
765 765 for (std::vector<QPDFObjectHandle>::iterator iter = contents.begin();
766 766 iter != contents.end(); ++iter)
... ... @@ -781,25 +781,25 @@ void runtest(int n, char const* filename1, char const* arg2)
781 781 }
782 782  
783 783 // Now insert the pages
784   - pdf.addPage(new_pages[0], true);
785   - checkPageContents(pages[0], "New page 1");
786   - pdf.addPageAt(new_pages[1], true, pages[0]);
787   - assert(pages[0].getObjGen() == new_pages[1].getObjGen());
788   - pdf.addPageAt(new_pages[2], true, pages[5]);
789   - assert(pages[5].getObjGen() == new_pages[2].getObjGen());
790   - pdf.addPageAt(new_pages[3], false, pages[5]);
791   - assert(pages[6].getObjGen() == new_pages[3].getObjGen());
  784 + pdf.addPage(new_pages.at(0), true);
  785 + checkPageContents(pages.at(0), "New page 1");
  786 + pdf.addPageAt(new_pages.at(1), true, pages.at(0));
  787 + assert(pages.at(0).getObjGen() == new_pages.at(1).getObjGen());
  788 + pdf.addPageAt(new_pages.at(2), true, pages.at(5));
  789 + assert(pages.at(5).getObjGen() == new_pages.at(2).getObjGen());
  790 + pdf.addPageAt(new_pages.at(3), false, pages.at(5));
  791 + assert(pages.at(6).getObjGen() == new_pages.at(3).getObjGen());
792 792 assert(pages.size() == 11);
793   - pdf.addPage(new_pages[4], false);
794   - assert(pages[11].getObjGen() == new_pages[4].getObjGen());
795   - pdf.addPageAt(new_pages[5], false, pages.back());
  793 + pdf.addPage(new_pages.at(4), false);
  794 + assert(pages.at(11).getObjGen() == new_pages.at(4).getObjGen());
  795 + pdf.addPageAt(new_pages.at(5), false, pages.back());
796 796 assert(pages.size() == 13);
797   - checkPageContents(pages[0], "New page 0");
798   - checkPageContents(pages[1], "New page 1");
799   - checkPageContents(pages[5], "New page 5");
800   - checkPageContents(pages[6], "New page 6");
801   - checkPageContents(pages[11], "New page 11");
802   - checkPageContents(pages[12], "New page 12");
  797 + checkPageContents(pages.at(0), "New page 0");
  798 + checkPageContents(pages.at(1), "New page 1");
  799 + checkPageContents(pages.at(5), "New page 5");
  800 + checkPageContents(pages.at(6), "New page 6");
  801 + checkPageContents(pages.at(11), "New page 11");
  802 + checkPageContents(pages.at(12), "New page 12");
803 803  
804 804 // Exercise writing to FILE*
805 805 FILE* out = QUtil::safe_fopen("a.pdf", "wb");
... ... @@ -816,7 +816,7 @@ void runtest(int n, char const* filename1, char const* arg2)
816 816 QPDFObjectHandle contents = createPageContents(pdf, "New page 10");
817 817 QPDFObjectHandle page =
818 818 pdf.makeIndirectObject(
819   - QPDFObjectHandle(all_pages[0]).shallowCopy());
  819 + QPDFObjectHandle(all_pages.at(0)).shallowCopy());
820 820 page.replaceKey("/Contents", contents);
821 821  
822 822 // Insert the page manually.
... ... @@ -843,7 +843,7 @@ void runtest(int n, char const* filename1, char const* arg2)
843 843 // The input file to this test case is broken to exercise an
844 844 // error condition.
845 845 std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
846   - pdf.removePage(pages[0]);
  846 + pdf.removePage(pages.at(0));
847 847 std::cout << "you can't see this" << std::endl;
848 848 }
849 849 else if (n == 18)
... ... @@ -854,7 +854,7 @@ void runtest(int n, char const* filename1, char const* arg2)
854 854 // Remove pages from various places, checking to make sure
855 855 // that our pages reference is getting updated.
856 856 assert(pages.size() == 10);
857   - QPDFObjectHandle page5 = pages[5];
  857 + QPDFObjectHandle page5 = pages.at(5);
858 858 pdf.removePage(page5);
859 859 pdf.addPage(page5, false);
860 860 assert(pages.size() == 10);
... ... @@ -871,7 +871,7 @@ void runtest(int n, char const* filename1, char const* arg2)
871 871 std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
872 872  
873 873 // Try to insert a page that's already there.
874   - pdf.addPage(pages[5], false);
  874 + pdf.addPage(pages.at(5), false);
875 875 std::cout << "you can't see this" << std::endl;
876 876 }
877 877 else if (n == 20)
... ... @@ -893,7 +893,7 @@ void runtest(int n, char const* filename1, char const* arg2)
893 893 {
894 894 // Try to shallow copy a stream
895 895 std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
896   - QPDFObjectHandle page = pages[0];
  896 + QPDFObjectHandle page = pages.at(0);
897 897 QPDFObjectHandle contents = page.getKey("/Contents");
898 898 contents.shallowCopy();
899 899 std::cout << "you can't see this" << std::endl;
... ... @@ -902,7 +902,7 @@ void runtest(int n, char const* filename1, char const* arg2)
902 902 {
903 903 // Try to remove a page we don't have
904 904 std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
905   - QPDFObjectHandle page = pages[0];
  905 + QPDFObjectHandle page = pages.at(0);
906 906 pdf.removePage(page);
907 907 pdf.removePage(page);
908 908 std::cout << "you can't see this" << std::endl;
... ... @@ -1109,9 +1109,9 @@ void runtest(int n, char const* filename1, char const* arg2)
1109 1109 QPDF final;
1110 1110 final.processFile("b.pdf", "user");
1111 1111 std::vector<QPDFObjectHandle> pages = pdf.getAllPages();
1112   - std::string orig_contents = getPageContents(pages[0]);
  1112 + std::string orig_contents = getPageContents(pages.at(0));
1113 1113 pages = final.getAllPages();
1114   - std::string new_contents = getPageContents(pages[0]);
  1114 + std::string new_contents = getPageContents(pages.at(0));
1115 1115 if (orig_contents != new_contents)
1116 1116 {
1117 1117 std::cout << "oops -- page contents don't match" << std::endl
... ... @@ -1226,7 +1226,7 @@ void runtest(int n, char const* filename1, char const* arg2)
1226 1226 bool is_binary = false;
1227 1227 for (size_t i = 0; i < data.size(); ++i)
1228 1228 {
1229   - if ((data[i] < 0) || (data[i] > 126))
  1229 + if ((data.at(i) < 0) || (data.at(i) > 126))
1230 1230 {
1231 1231 is_binary = true;
1232 1232 break;
... ... @@ -1239,9 +1239,9 @@ void runtest(int n, char const* filename1, char const* arg2)
1239 1239 i < std::min(data.size(), static_cast<size_t>(20));
1240 1240 ++i)
1241 1241 {
1242   - if ((data[i] >= 32) && (data[i] <= 126))
  1242 + if ((data.at(i) >= 32) && (data.at(i) <= 126))
1243 1243 {
1244   - t += data[i];
  1244 + t += data.at(i);
1245 1245 }
1246 1246 else
1247 1247 {
... ...
qpdf/test_large_file.cc
... ... @@ -286,8 +286,8 @@ static void check_pdf(char const* filename)
286 286 {
287 287 int pageno = i + 1;
288 288 std::cout << "page " << pageno << " of " << npages << std::endl;
289   - check_page_contents(pageno, pages[i]);
290   - check_image(pageno, pages[i]);
  289 + check_page_contents(pageno, pages.at(i));
  290 + check_image(pageno, pages.at(i));
291 291 }
292 292 }
293 293  
... ...