Commit 0db65e79120e66069a37906845a984457b711b6f
1 parent
13672260
Remove temporary OHArray::disconnect and setAt
Showing
4 changed files
with
12 additions
and
26 deletions
include/qpdf/QPDFObjectHandle.hh
| ... | ... | @@ -1494,14 +1494,14 @@ class QPDFObjectHandle |
| 1494 | 1494 | // disconnected(). |
| 1495 | 1495 | class DisconnectAccess |
| 1496 | 1496 | { |
| 1497 | + friend class QPDF_Array; | |
| 1497 | 1498 | friend class QPDF_Dictionary; |
| 1498 | 1499 | friend class QPDF_Stream; |
| 1499 | 1500 | friend class SparseOHArray; |
| 1500 | - friend class OHArray; | |
| 1501 | 1501 | |
| 1502 | 1502 | private: |
| 1503 | 1503 | static void |
| 1504 | - disconnect(QPDFObjectHandle& o) | |
| 1504 | + disconnect(QPDFObjectHandle o) | |
| 1505 | 1505 | { |
| 1506 | 1506 | o.disconnect(); |
| 1507 | 1507 | } | ... | ... |
libqpdf/OHArray.cc
| ... | ... | @@ -12,26 +12,6 @@ OHArray::OHArray() |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | void |
| 15 | -OHArray::disconnect() | |
| 16 | -{ | |
| 17 | - for (auto const& iter: elements) { | |
| 18 | - if (iter) { | |
| 19 | - QPDFObjectHandle oh = iter; | |
| 20 | - QPDFObjectHandle::DisconnectAccess::disconnect(oh); | |
| 21 | - } | |
| 22 | - } | |
| 23 | -} | |
| 24 | - | |
| 25 | -void | |
| 26 | -OHArray::setAt(size_t idx, QPDFObjectHandle oh) | |
| 27 | -{ | |
| 28 | - if (idx >= elements.size()) { | |
| 29 | - throw std::logic_error("bounds error setting item in OHArray"); | |
| 30 | - } | |
| 31 | - elements[idx] = oh.getObj(); | |
| 32 | -} | |
| 33 | - | |
| 34 | -void | |
| 35 | 15 | OHArray::erase(size_t idx) |
| 36 | 16 | { |
| 37 | 17 | if (idx >= elements.size()) { | ... | ... |
libqpdf/QPDF_Array.cc
| ... | ... | @@ -77,7 +77,11 @@ QPDF_Array::disconnect() |
| 77 | 77 | if (sparse) { |
| 78 | 78 | sp_elements.disconnect(); |
| 79 | 79 | } else { |
| 80 | - elements.disconnect(); | |
| 80 | + for (auto const& iter: elements.elements) { | |
| 81 | + if (iter) { | |
| 82 | + QPDFObjectHandle::DisconnectAccess::disconnect(iter); | |
| 83 | + } | |
| 84 | + } | |
| 81 | 85 | } |
| 82 | 86 | } |
| 83 | 87 | |
| ... | ... | @@ -176,7 +180,11 @@ QPDF_Array::setItem(int n, QPDFObjectHandle const& oh) |
| 176 | 180 | if (sparse) { |
| 177 | 181 | sp_elements.setAt(QIntC::to_size(n), oh); |
| 178 | 182 | } else { |
| 179 | - elements.setAt(QIntC::to_size(n), oh); | |
| 183 | + size_t idx = size_t(n); | |
| 184 | + if (n < 0 || idx >= elements.elements.size()) { | |
| 185 | + throw std::logic_error("bounds error setting item in QPDF_Array"); | |
| 186 | + } | |
| 187 | + elements.elements[idx] = oh.getObj(); | |
| 180 | 188 | } |
| 181 | 189 | } |
| 182 | 190 | ... | ... |
libqpdf/qpdf/OHArray.hh
| ... | ... | @@ -12,11 +12,9 @@ class OHArray |
| 12 | 12 | { |
| 13 | 13 | public: |
| 14 | 14 | OHArray(); |
| 15 | - void setAt(size_t idx, QPDFObjectHandle oh); | |
| 16 | 15 | void erase(size_t idx); |
| 17 | 16 | void insert(size_t idx, QPDFObjectHandle oh); |
| 18 | 17 | OHArray copy(); |
| 19 | - void disconnect(); | |
| 20 | 18 | |
| 21 | 19 | private: |
| 22 | 20 | friend class QPDF_Array; | ... | ... |