diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 4e2813f..ddbeba5 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -174,8 +174,10 @@ Array::null() const size_t Array::size() const { - auto a = array(); - return a->sp ? a->sp->size : a->elements.size(); + if (auto a = as()) { + return a->sp ? a->sp->size : a->elements.size(); + } + return 0; } std::pair diff --git a/libqpdf/qpdf/QPDFObjectHandle_private.hh b/libqpdf/qpdf/QPDFObjectHandle_private.hh index 74872b4..447754b 100644 --- a/libqpdf/qpdf/QPDFObjectHandle_private.hh +++ b/libqpdf/qpdf/QPDFObjectHandle_private.hh @@ -86,6 +86,7 @@ namespace qpdf const_reverse_iterator crend(); + // Return the number of elements in the array. Return 0 if the object is not an array. size_t size() const; std::pair at(int n) const; bool setAt(int at, QPDFObjectHandle const& oh);