Commit 4ae93a73c5bbf36cf2b36712b0df7acabbc1e61a

Authored by Jay Berkenbilt
1 parent 1fec4045

Improve memory safety of dict/array iterators

examples/pdf-mod-info.cc
@@ -39,8 +39,7 @@ void dumpInfoDict(QPDF& pdf, @@ -39,8 +39,7 @@ void dumpInfoDict(QPDF& pdf,
39 QPDFObjectHandle trailer = pdf.getTrailer(); 39 QPDFObjectHandle trailer = pdf.getTrailer();
40 if (trailer.hasKey("/Info")) 40 if (trailer.hasKey("/Info"))
41 { 41 {
42 - QPDFObjectHandle info = trailer.getKey("/Info");  
43 - for (auto& it: QPDFDictItems(info)) 42 + for (auto& it: QPDFDictItems(trailer.getKey("/Info")))
44 { 43 {
45 std::string val; 44 std::string val;
46 if (it.second.isString()) 45 if (it.second.isString())
include/qpdf/QPDFObjectHandle.hh
@@ -1242,7 +1242,7 @@ class QPDFDictItems @@ -1242,7 +1242,7 @@ class QPDFDictItems
1242 1242
1243 public: 1243 public:
1244 QPDF_DLL 1244 QPDF_DLL
1245 - QPDFDictItems(QPDFObjectHandle& oh); 1245 + QPDFDictItems(QPDFObjectHandle const& oh);
1246 1246
1247 class iterator: public std::iterator< 1247 class iterator: public std::iterator<
1248 std::bidirectional_iterator_tag, 1248 std::bidirectional_iterator_tag,
@@ -1314,7 +1314,7 @@ class QPDFDictItems @@ -1314,7 +1314,7 @@ class QPDFDictItems
1314 iterator end(); 1314 iterator end();
1315 1315
1316 private: 1316 private:
1317 - QPDFObjectHandle& oh; 1317 + QPDFObjectHandle oh;
1318 }; 1318 };
1319 1319
1320 class QPDFArrayItems 1320 class QPDFArrayItems
@@ -1332,7 +1332,7 @@ class QPDFArrayItems @@ -1332,7 +1332,7 @@ class QPDFArrayItems
1332 1332
1333 public: 1333 public:
1334 QPDF_DLL 1334 QPDF_DLL
1335 - QPDFArrayItems(QPDFObjectHandle& oh); 1335 + QPDFArrayItems(QPDFObjectHandle const& oh);
1336 1336
1337 class iterator: public std::iterator< 1337 class iterator: public std::iterator<
1338 std::bidirectional_iterator_tag, 1338 std::bidirectional_iterator_tag,
@@ -1403,7 +1403,7 @@ class QPDFArrayItems @@ -1403,7 +1403,7 @@ class QPDFArrayItems
1403 iterator end(); 1403 iterator end();
1404 1404
1405 private: 1405 private:
1406 - QPDFObjectHandle& oh; 1406 + QPDFObjectHandle oh;
1407 }; 1407 };
1408 1408
1409 1409
libqpdf/QPDFObjectHandle.cc
@@ -3080,7 +3080,7 @@ QPDFObjectHandle::warn(QPDF* qpdf, QPDFExc const&amp; e) @@ -3080,7 +3080,7 @@ QPDFObjectHandle::warn(QPDF* qpdf, QPDFExc const&amp; e)
3080 } 3080 }
3081 } 3081 }
3082 3082
3083 -QPDFDictItems::QPDFDictItems(QPDFObjectHandle& oh) : 3083 +QPDFDictItems::QPDFDictItems(QPDFObjectHandle const& oh) :
3084 oh(oh) 3084 oh(oh)
3085 { 3085 {
3086 } 3086 }
@@ -3171,7 +3171,7 @@ QPDFDictItems::end() @@ -3171,7 +3171,7 @@ QPDFDictItems::end()
3171 return iterator(oh, false); 3171 return iterator(oh, false);
3172 } 3172 }
3173 3173
3174 -QPDFArrayItems::QPDFArrayItems(QPDFObjectHandle& oh) : 3174 +QPDFArrayItems::QPDFArrayItems(QPDFObjectHandle const& oh) :
3175 oh(oh) 3175 oh(oh)
3176 { 3176 {
3177 } 3177 }