summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfdoc/cpdf_structelement.cpp7
-rw-r--r--core/fpdfdoc/cpdf_structelement.h4
-rw-r--r--fpdfsdk/fpdf_structtree.cpp10
3 files changed, 12 insertions, 9 deletions
diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp
index 0b0b542852..13985b8fed 100644
--- a/core/fpdfdoc/cpdf_structelement.cpp
+++ b/core/fpdfdoc/cpdf_structelement.cpp
@@ -14,7 +14,6 @@
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfdoc/cpdf_structtree.h"
-#include "third_party/base/stl_util.h"
CPDF_StructKid::CPDF_StructKid()
: m_Type(Invalid),
@@ -45,11 +44,11 @@ CPDF_StructElement::CPDF_StructElement(CPDF_StructTree* pTree,
CPDF_StructElement::~CPDF_StructElement() = default;
-int CPDF_StructElement::CountKids() const {
- return pdfium::CollectionSize<int>(m_Kids);
+size_t CPDF_StructElement::CountKids() const {
+ return m_Kids.size();
}
-CPDF_StructElement* CPDF_StructElement::GetKidIfElement(int index) const {
+CPDF_StructElement* CPDF_StructElement::GetKidIfElement(size_t index) const {
return m_Kids[index].m_Type == CPDF_StructKid::Element
? m_Kids[index].m_pElement.Get()
: nullptr;
diff --git a/core/fpdfdoc/cpdf_structelement.h b/core/fpdfdoc/cpdf_structelement.h
index 57f8aee2e8..51ee93bd54 100644
--- a/core/fpdfdoc/cpdf_structelement.h
+++ b/core/fpdfdoc/cpdf_structelement.h
@@ -43,8 +43,8 @@ class CPDF_StructElement : public Retainable {
const ByteString& GetTitle() const { return m_Title; }
CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
- int CountKids() const;
- CPDF_StructElement* GetKidIfElement(int index) const;
+ size_t CountKids() const;
+ CPDF_StructElement* GetKidIfElement(size_t index) const;
std::vector<CPDF_StructKid>* GetKids() { return &m_Kids; }
private:
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp
index b1fca65015..483d894f6e 100644
--- a/fpdfsdk/fpdf_structtree.cpp
+++ b/fpdfsdk/fpdf_structtree.cpp
@@ -99,15 +99,19 @@ FPDF_StructElement_GetTitle(FPDF_STRUCTELEMENT struct_element,
FPDF_EXPORT int FPDF_CALLCONV
FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element) {
CPDF_StructElement* elem = ToStructTreeElement(struct_element);
- return elem ? elem->CountKids() : -1;
+ if (!elem)
+ return -1;
+
+ pdfium::base::CheckedNumeric<int> tmp_size = elem->CountKids();
+ return tmp_size.ValueOrDefault(-1);
}
FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV
FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element,
int index) {
CPDF_StructElement* elem = ToStructTreeElement(struct_element);
- if (!elem || index < 0 || index >= elem->CountKids())
+ if (!elem || index < 0 || static_cast<size_t>(index) >= elem->CountKids())
return nullptr;
- return elem->GetKidIfElement(index);
+ return elem->GetKidIfElement(static_cast<size_t>(index));
}