summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfdoc/cpdf_structtree.cpp9
-rw-r--r--core/fpdfdoc/cpdf_structtree.h4
-rw-r--r--fpdfsdk/fpdf_structtree.cpp12
3 files changed, 11 insertions, 14 deletions
diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp
index 0e9b529ca8..48b83f555c 100644
--- a/core/fpdfdoc/cpdf_structtree.cpp
+++ b/core/fpdfdoc/cpdf_structtree.cpp
@@ -12,7 +12,6 @@
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfdoc/cpdf_numbertree.h"
#include "core/fpdfdoc/cpdf_structelement.h"
-#include "third_party/base/stl_util.h"
namespace {
@@ -45,14 +44,6 @@ CPDF_StructTree::CPDF_StructTree(const CPDF_Document* pDoc)
CPDF_StructTree::~CPDF_StructTree() {}
-int CPDF_StructTree::CountTopElements() const {
- return pdfium::CollectionSize<int>(m_Kids);
-}
-
-CPDF_StructElement* CPDF_StructTree::GetTopElement(int i) const {
- return m_Kids[i].Get();
-}
-
void CPDF_StructTree::LoadPageTree(const CPDF_Dictionary* pPageDict) {
m_pPage = pPageDict;
if (!m_pTreeRoot)
diff --git a/core/fpdfdoc/cpdf_structtree.h b/core/fpdfdoc/cpdf_structtree.h
index 9f1d50e066..99342fb6de 100644
--- a/core/fpdfdoc/cpdf_structtree.h
+++ b/core/fpdfdoc/cpdf_structtree.h
@@ -27,8 +27,8 @@ class CPDF_StructTree {
explicit CPDF_StructTree(const CPDF_Document* pDoc);
~CPDF_StructTree();
- int CountTopElements() const;
- CPDF_StructElement* GetTopElement(int i) const;
+ size_t CountTopElements() const { return m_Kids.size(); }
+ CPDF_StructElement* GetTopElement(size_t i) const { return m_Kids[i].Get(); }
const CPDF_Dictionary* GetRoleMap() const { return m_pRoleMap.Get(); }
const CPDF_Dictionary* GetPage() const { return m_pPage.Get(); }
const CPDF_Dictionary* GetTreeRoot() const { return m_pTreeRoot.Get(); }
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp
index 483d894f6e..30b7c3fce7 100644
--- a/fpdfsdk/fpdf_structtree.cpp
+++ b/fpdfsdk/fpdf_structtree.cpp
@@ -55,15 +55,21 @@ FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree) {
FPDF_EXPORT int FPDF_CALLCONV
FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) {
CPDF_StructTree* tree = ToStructTree(struct_tree);
- return tree ? tree->CountTopElements() : -1;
+ if (!tree)
+ return -1;
+
+ pdfium::base::CheckedNumeric<int> tmp_size = tree->CountTopElements();
+ return tmp_size.ValueOrDefault(-1);
}
FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV
FPDF_StructTree_GetChildAtIndex(FPDF_STRUCTTREE struct_tree, int index) {
CPDF_StructTree* tree = ToStructTree(struct_tree);
- if (!tree || index < 0 || index >= tree->CountTopElements())
+ if (!tree || index < 0 ||
+ static_cast<size_t>(index) >= tree->CountTopElements()) {
return nullptr;
- return tree->GetTopElement(index);
+ }
+ return tree->GetTopElement(static_cast<size_t>(index));
}
FPDF_EXPORT unsigned long FPDF_CALLCONV