Commit 62d1dd6d6e1b5d0f9b08795639ebb7c0f250398b

Authored by m-holger
1 parent 1f3f872d

Redefine `Array::size()` to return 0 if the object is not an array

libqpdf/QPDF_Array.cc
@@ -174,8 +174,10 @@ Array::null() const @@ -174,8 +174,10 @@ Array::null() const
174 size_t 174 size_t
175 Array::size() const 175 Array::size() const
176 { 176 {
177 - auto a = array();  
178 - return a->sp ? a->sp->size : a->elements.size(); 177 + if (auto a = as<QPDF_Array>()) {
  178 + return a->sp ? a->sp->size : a->elements.size();
  179 + }
  180 + return 0;
179 } 181 }
180 182
181 std::pair<bool, QPDFObjectHandle> 183 std::pair<bool, QPDFObjectHandle>
libqpdf/qpdf/QPDFObjectHandle_private.hh
@@ -86,6 +86,7 @@ namespace qpdf @@ -86,6 +86,7 @@ namespace qpdf
86 86
87 const_reverse_iterator crend(); 87 const_reverse_iterator crend();
88 88
  89 + // Return the number of elements in the array. Return 0 if the object is not an array.
89 size_t size() const; 90 size_t size() const;
90 std::pair<bool, QPDFObjectHandle> at(int n) const; 91 std::pair<bool, QPDFObjectHandle> at(int n) const;
91 bool setAt(int at, QPDFObjectHandle const& oh); 92 bool setAt(int at, QPDFObjectHandle const& oh);