summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-01-04 13:57:02 -0500
committerChromium commit bot <commit-bot@chromium.org>2018-01-04 19:15:31 +0000
commitcb6c8d4ec4781c7db8448f2b4d9a8af879cf014e (patch)
treede752e161b1196c6b26b2f34418b7dff7ee39b64
parent981a2908d7a213363772d1846a7c63c2cfd73c7e (diff)
downloadpdfium-cb6c8d4ec4781c7db8448f2b4d9a8af879cf014e.tar.xz
Make CXFA_List::GetLength return a size_t
This requires a number of other minor cleanups to get sizes and signedness agreeing everywhere. Change-Id: Ie25318a23d458be5a8a2a91927c3b37eb198f5ce Reviewed-on: https://pdfium-review.googlesource.com/22256 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
-rw-r--r--fxjs/xfa/cjx_list.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_arraynodelist.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_arraynodelist.h2
-rw-r--r--xfa/fxfa/parser/cxfa_attachnodelist.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_attachnodelist.h2
-rw-r--r--xfa/fxfa/parser/cxfa_list.h2
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp8
-rw-r--r--xfa/fxfa/parser/cxfa_node.h2
-rw-r--r--xfa/fxfa/parser/cxfa_treelist.cpp7
9 files changed, 19 insertions, 16 deletions
diff --git a/fxjs/xfa/cjx_list.cpp b/fxjs/xfa/cjx_list.cpp
index 198804dbed..57087a8492 100644
--- a/fxjs/xfa/cjx_list.cpp
+++ b/fxjs/xfa/cjx_list.cpp
@@ -11,6 +11,7 @@
#include "fxjs/cfxjse_engine.h"
#include "fxjs/cfxjse_value.h"
#include "fxjs/js_resources.h"
+#include "third_party/base/numerics/safe_conversions.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_list.h"
#include "xfa/fxfa/parser/cxfa_node.h"
@@ -76,7 +77,7 @@ CJS_Return CJX_List::item(CJS_V8* runtime,
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
int32_t iIndex = runtime->ToInt32(params[0]);
- if (iIndex < 0 || iIndex >= GetXFAList()->GetLength())
+ if (iIndex < 0 || static_cast<size_t>(iIndex) >= GetXFAList()->GetLength())
return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError));
return CJS_Return(runtime->NewXFAObject(
@@ -91,5 +92,6 @@ void CJX_List::length(CFXJSE_Value* pValue,
ThrowInvalidPropertyException();
return;
}
- pValue->SetInteger(GetXFAList()->GetLength());
+ pValue->SetInteger(
+ pdfium::base::checked_cast<int32_t>(GetXFAList()->GetLength()));
}
diff --git a/xfa/fxfa/parser/cxfa_arraynodelist.cpp b/xfa/fxfa/parser/cxfa_arraynodelist.cpp
index 3b32d8f022..9ea36d3c24 100644
--- a/xfa/fxfa/parser/cxfa_arraynodelist.cpp
+++ b/xfa/fxfa/parser/cxfa_arraynodelist.cpp
@@ -21,8 +21,8 @@ void CXFA_ArrayNodeList::SetArrayNodeList(
m_array = srcArray;
}
-int32_t CXFA_ArrayNodeList::GetLength() {
- return pdfium::CollectionSize<int32_t>(m_array);
+size_t CXFA_ArrayNodeList::GetLength() {
+ return m_array.size();
}
bool CXFA_ArrayNodeList::Append(CXFA_Node* pNode) {
diff --git a/xfa/fxfa/parser/cxfa_arraynodelist.h b/xfa/fxfa/parser/cxfa_arraynodelist.h
index 0ebe0c6af6..caee762e29 100644
--- a/xfa/fxfa/parser/cxfa_arraynodelist.h
+++ b/xfa/fxfa/parser/cxfa_arraynodelist.h
@@ -20,7 +20,7 @@ class CXFA_ArrayNodeList : public CXFA_TreeList {
~CXFA_ArrayNodeList() override;
// From CXFA_TreeList.
- int32_t GetLength() override;
+ size_t GetLength() override;
bool Append(CXFA_Node* pNode) override;
bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override;
bool Remove(CXFA_Node* pNode) override;
diff --git a/xfa/fxfa/parser/cxfa_attachnodelist.cpp b/xfa/fxfa/parser/cxfa_attachnodelist.cpp
index 0a9be2ed4a..3666b99bd4 100644
--- a/xfa/fxfa/parser/cxfa_attachnodelist.cpp
+++ b/xfa/fxfa/parser/cxfa_attachnodelist.cpp
@@ -14,7 +14,7 @@ CXFA_AttachNodeList::CXFA_AttachNodeList(CXFA_Document* pDocument,
m_pAttachNode = pAttachNode;
}
-int32_t CXFA_AttachNodeList::GetLength() {
+size_t CXFA_AttachNodeList::GetLength() {
return m_pAttachNode->CountChildren(
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 a657150f43..390ea041b9 100644
--- a/xfa/fxfa/parser/cxfa_attachnodelist.h
+++ b/xfa/fxfa/parser/cxfa_attachnodelist.h
@@ -17,7 +17,7 @@ class CXFA_AttachNodeList : public CXFA_TreeList {
CXFA_AttachNodeList(CXFA_Document* pDocument, CXFA_Node* pAttachNode);
// From CXFA_TreeList.
- int32_t GetLength() override;
+ size_t GetLength() override;
bool Append(CXFA_Node* pNode) override;
bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override;
bool Remove(CXFA_Node* pNode) override;
diff --git a/xfa/fxfa/parser/cxfa_list.h b/xfa/fxfa/parser/cxfa_list.h
index 5736747dba..953e861835 100644
--- a/xfa/fxfa/parser/cxfa_list.h
+++ b/xfa/fxfa/parser/cxfa_list.h
@@ -17,7 +17,7 @@ class CXFA_List : public CXFA_Object {
public:
~CXFA_List() override;
- virtual int32_t GetLength() = 0;
+ virtual size_t GetLength() = 0;
virtual bool Append(CXFA_Node* pNode) = 0;
virtual bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) = 0;
virtual bool Remove(CXFA_Node* pNode) = 0;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index d7d187d168..f6f2675c29 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -784,17 +784,17 @@ CXFA_Node* CXFA_Node::GetModelNode() {
}
}
-int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
- int32_t iCount = 0;
+size_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
+ size_t count = 0;
for (CXFA_Node* pNode = m_pChild; pNode;
pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
if (pNode->GetElementType() != eType && eType != XFA_Element::Unknown)
continue;
if (bOnlyChild && HasProperty(pNode->GetElementType()))
continue;
- ++iCount;
+ ++count;
}
- return iCount;
+ return count;
}
CXFA_Node* CXFA_Node::GetChildInternal(int32_t index,
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 794e5fc032..e6683b24dc 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -154,7 +154,7 @@ class CXFA_Node : public CXFA_Object {
CXFA_Node* GetModelNode();
void UpdateNameHash();
- int32_t CountChildren(XFA_Element eType, bool bOnlyChild);
+ size_t CountChildren(XFA_Element eType, bool bOnlyChild);
template <typename T>
T* GetChild(int32_t index, XFA_Element eType, bool bOnlyChild) {
diff --git a/xfa/fxfa/parser/cxfa_treelist.cpp b/xfa/fxfa/parser/cxfa_treelist.cpp
index 754c80d661..941020fe27 100644
--- a/xfa/fxfa/parser/cxfa_treelist.cpp
+++ b/xfa/fxfa/parser/cxfa_treelist.cpp
@@ -11,6 +11,7 @@
#include "core/fxcrt/fx_extension.h"
#include "fxjs/cfxjse_engine.h"
#include "fxjs/xfa/cjx_treelist.h"
+#include "third_party/base/numerics/safe_conversions.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_list.h"
#include "xfa/fxfa/parser/cxfa_node.h"
@@ -26,9 +27,9 @@ CXFA_TreeList::~CXFA_TreeList() {}
CXFA_Node* CXFA_TreeList::NamedItem(const WideStringView& wsName) {
uint32_t dwHashCode = FX_HashCode_GetW(wsName, false);
- int32_t iCount = GetLength();
- for (int32_t i = 0; i < iCount; i++) {
- CXFA_Node* ret = Item(i);
+ size_t count = GetLength();
+ for (size_t i = 0; i < count; i++) {
+ CXFA_Node* ret = Item(pdfium::base::checked_cast<int32_t>(i));
if (dwHashCode == ret->GetNameHash())
return ret;
}