summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-11 14:51:11 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-11 14:51:11 +0000
commit61dfd72ab3a913b143c03bdcf4ec5816dcb09cd1 (patch)
treeecad6d7951ca1f9b09f7674e3675048043adaa45 /xfa/fxfa/parser
parent7d2c5f4c8d33d57b76af1c471e70af36db090072 (diff)
downloadpdfium-61dfd72ab3a913b143c03bdcf4ec5816dcb09cd1.tar.xz
Rename GetItem to GetItemIfExists
Rename GetItem to make it clearer it can return nullptr. Change-Id: I0e09a79c3e2244b08212d3b51d3ad0e6a86edfd9 Reviewed-on: https://pdfium-review.googlesource.com/22713 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp15
-rw-r--r--xfa/fxfa/parser/cxfa_node.h2
2 files changed, 13 insertions, 4 deletions
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index c29e30347f..075ee46836 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1129,7 +1129,7 @@ bool CXFA_Node::IsNeedSavingXMLNode() {
GetElementType() == XFA_Element::Xfa);
}
-CXFA_Node* CXFA_Node::GetItem(int32_t iIndex) {
+CXFA_Node* CXFA_Node::GetItemIfExists(int32_t iIndex) {
int32_t iCount = 0;
uint32_t dwNameHash = 0;
for (CXFA_Node* pNode = GetNextSibling(); pNode;
@@ -1198,8 +1198,12 @@ void CXFA_Node::InsertItem(CXFA_Node* pNewInstance,
if (iPos < 0)
iPos = iCount;
if (iPos == iCount) {
+ CXFA_Node* item = GetItemIfExists(iCount - 1);
+ if (!item)
+ return;
+
CXFA_Node* pNextSibling =
- iCount > 0 ? GetItem(iCount - 1)->GetNextSibling() : GetNextSibling();
+ iCount > 0 ? item->GetNextSibling() : GetNextSibling();
GetParent()->InsertChild(pNewInstance, pNextSibling);
if (bMoveDataBindingNodes) {
std::set<CXFA_Node*> sNew;
@@ -1229,7 +1233,12 @@ void CXFA_Node::InsertItem(CXFA_Node* pNewInstance,
ReorderDataNodes(sNew, sAfter, false);
}
} else {
- CXFA_Node* pBeforeInstance = GetItem(iPos);
+ CXFA_Node* pBeforeInstance = GetItemIfExists(iPos);
+ if (!pBeforeInstance) {
+ // TODO(dsinclair): What should happen here?
+ return;
+ }
+
GetParent()->InsertChild(pNewInstance, pBeforeInstance);
if (bMoveDataBindingNodes) {
std::set<CXFA_Node*> sNew;
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 1e20ace09c..8108eeccc4 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -104,7 +104,7 @@ class CXFA_Node : public CXFA_Object {
CXFA_Node* CreateInstanceIfPossible(bool bDataMerge);
int32_t GetCount();
- CXFA_Node* GetItem(int32_t iIndex);
+ CXFA_Node* GetItemIfExists(int32_t iIndex);
void RemoveItem(CXFA_Node* pRemoveInstance, bool bRemoveDataBinding);
void InsertItem(CXFA_Node* pNewInstance,
int32_t iPos,