Make indices for CXFA_List be size_t instead of int32_t

Change-Id: Id825e027a337636bb779f09bc0b1c6985a781fa1
Reviewed-on: https://pdfium-review.googlesource.com/22257
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/fxjs/xfa/cjx_list.cpp b/fxjs/xfa/cjx_list.cpp
index 57087a8..9cbd32d 100644
--- a/fxjs/xfa/cjx_list.cpp
+++ b/fxjs/xfa/cjx_list.cpp
@@ -76,12 +76,13 @@
   if (params.size() != 1)
     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
 
-  int32_t iIndex = runtime->ToInt32(params[0]);
-  if (iIndex < 0 || static_cast<size_t>(iIndex) >= GetXFAList()->GetLength())
+  int32_t index = runtime->ToInt32(params[0]);
+  size_t cast_index = static_cast<size_t>(index);
+  if (index < 0 || cast_index >= GetXFAList()->GetLength())
     return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError));
 
   return CJS_Return(runtime->NewXFAObject(
-      GetXFAList()->Item(iIndex),
+      GetXFAList()->Item(cast_index),
       GetDocument()->GetScriptContext()->GetJseNormalClass()->GetTemplate()));
 }
 
diff --git a/xfa/fxfa/parser/cxfa_arraynodelist.cpp b/xfa/fxfa/parser/cxfa_arraynodelist.cpp
index 9ea36d3..9eaf9a6 100644
--- a/xfa/fxfa/parser/cxfa_arraynodelist.cpp
+++ b/xfa/fxfa/parser/cxfa_arraynodelist.cpp
@@ -48,7 +48,6 @@
   return true;
 }
 
-CXFA_Node* CXFA_ArrayNodeList::Item(int32_t iIndex) {
-  int32_t iSize = pdfium::CollectionSize<int32_t>(m_array);
-  return (iIndex >= 0 && iIndex < iSize) ? m_array[iIndex] : nullptr;
+CXFA_Node* CXFA_ArrayNodeList::Item(size_t index) {
+  return index < m_array.size() ? m_array[index] : nullptr;
 }
diff --git a/xfa/fxfa/parser/cxfa_arraynodelist.h b/xfa/fxfa/parser/cxfa_arraynodelist.h
index caee762..346b206 100644
--- a/xfa/fxfa/parser/cxfa_arraynodelist.h
+++ b/xfa/fxfa/parser/cxfa_arraynodelist.h
@@ -24,7 +24,7 @@
   bool Append(CXFA_Node* pNode) override;
   bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override;
   bool Remove(CXFA_Node* pNode) override;
-  CXFA_Node* Item(int32_t iIndex) override;
+  CXFA_Node* Item(size_t iIndex) override;
 
   void SetArrayNodeList(const std::vector<CXFA_Node*>& srcArray);
 
diff --git a/xfa/fxfa/parser/cxfa_attachnodelist.cpp b/xfa/fxfa/parser/cxfa_attachnodelist.cpp
index 3666b99..2a47411 100644
--- a/xfa/fxfa/parser/cxfa_attachnodelist.cpp
+++ b/xfa/fxfa/parser/cxfa_attachnodelist.cpp
@@ -6,6 +6,7 @@
 
 #include "xfa/fxfa/parser/cxfa_attachnodelist.h"
 
+#include "third_party/base/numerics/safe_conversions.h"
 #include "xfa/fxfa/parser/cxfa_node.h"
 
 CXFA_AttachNodeList::CXFA_AttachNodeList(CXFA_Document* pDocument,
@@ -40,8 +41,8 @@
   return m_pAttachNode->RemoveChild(pNode, true);
 }
 
-CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) {
+CXFA_Node* CXFA_AttachNodeList::Item(size_t index) {
   return m_pAttachNode->GetChild<CXFA_Node>(
-      iIndex, XFA_Element::Unknown,
+      pdfium::base::checked_cast<int32_t>(index), XFA_Element::Unknown,
       m_pAttachNode->GetElementType() == XFA_Element::Subform);
 }
diff --git a/xfa/fxfa/parser/cxfa_attachnodelist.h b/xfa/fxfa/parser/cxfa_attachnodelist.h
index 390ea04..f0df2bb 100644
--- a/xfa/fxfa/parser/cxfa_attachnodelist.h
+++ b/xfa/fxfa/parser/cxfa_attachnodelist.h
@@ -21,7 +21,7 @@
   bool Append(CXFA_Node* pNode) override;
   bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override;
   bool Remove(CXFA_Node* pNode) override;
-  CXFA_Node* Item(int32_t iIndex) override;
+  CXFA_Node* Item(size_t iIndex) override;
 
  private:
   CXFA_Node* m_pAttachNode;
diff --git a/xfa/fxfa/parser/cxfa_list.h b/xfa/fxfa/parser/cxfa_list.h
index 953e861..de9406d 100644
--- a/xfa/fxfa/parser/cxfa_list.h
+++ b/xfa/fxfa/parser/cxfa_list.h
@@ -21,7 +21,7 @@
   virtual bool Append(CXFA_Node* pNode) = 0;
   virtual bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) = 0;
   virtual bool Remove(CXFA_Node* pNode) = 0;
-  virtual CXFA_Node* Item(int32_t iIndex) = 0;
+  virtual CXFA_Node* Item(size_t iIndex) = 0;
 
  protected:
   CXFA_List(CXFA_Document* doc, std::unique_ptr<CJX_Object> js_obj);
diff --git a/xfa/fxfa/parser/cxfa_treelist.cpp b/xfa/fxfa/parser/cxfa_treelist.cpp
index 941020f..5db9ecb 100644
--- a/xfa/fxfa/parser/cxfa_treelist.cpp
+++ b/xfa/fxfa/parser/cxfa_treelist.cpp
@@ -29,7 +29,7 @@
   uint32_t dwHashCode = FX_HashCode_GetW(wsName, false);
   size_t count = GetLength();
   for (size_t i = 0; i < count; i++) {
-    CXFA_Node* ret = Item(pdfium::base::checked_cast<int32_t>(i));
+    CXFA_Node* ret = Item(i);
     if (dwHashCode == ret->GetNameHash())
       return ret;
   }