summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml/cfx_xmlnode.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-05-01 17:01:54 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-01 17:01:54 +0000
commit048afc6aba4848d5296affb4335500f960262580 (patch)
tree1cef231f4c264542412b8ad67db4f622f8eea81d /core/fxcrt/xml/cfx_xmlnode.cpp
parentb5902c78075141d9d569a463486d20ccabd78a2d (diff)
downloadpdfium-048afc6aba4848d5296affb4335500f960262580.tar.xz
Fix CFX_XML and add unit tests
This CL fixes several issues in the CFX_XML class and adds unit tests. Change-Id: I05270690de8f3c45dceb866e17ef899ae6d23389 Reviewed-on: https://pdfium-review.googlesource.com/31753 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fxcrt/xml/cfx_xmlnode.cpp')
-rw-r--r--core/fxcrt/xml/cfx_xmlnode.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp
index 4f811e608e..088cbf367c 100644
--- a/core/fxcrt/xml/cfx_xmlnode.cpp
+++ b/core/fxcrt/xml/cfx_xmlnode.cpp
@@ -27,8 +27,18 @@ void CFX_XMLNode::DeleteChildren() {
last_child_ = nullptr;
while (child) {
child = child->prev_sibling_.Get();
- if (child)
+ if (child) {
+ if (child->next_sibling_) {
+ child->next_sibling_->prev_sibling_ = nullptr;
+ child->next_sibling_->parent_ = nullptr;
+ }
+
child->next_sibling_ = nullptr;
+ }
+ }
+ if (first_child_) {
+ first_child_->next_sibling_ = nullptr;
+ first_child_->parent_ = nullptr;
}
first_child_ = nullptr;
}
@@ -82,21 +92,30 @@ void CFX_XMLNode::RemoveChildNode(CFX_XMLNode* pNode) {
ASSERT(first_child_);
ASSERT(pNode);
+ if (pNode->GetParent() != this)
+ return;
+
if (first_child_.get() == pNode) {
first_child_.release();
first_child_ = std::move(pNode->next_sibling_);
+ if (first_child_) {
+ first_child_->prev_sibling_ = nullptr;
+
+ if (first_child_->next_sibling_)
+ first_child_->next_sibling_->prev_sibling_ = first_child_.get();
+ }
} else {
CFX_XMLNode* prev = pNode->prev_sibling_.Get();
prev->next_sibling_.release(); // Release pNode
prev->next_sibling_ = std::move(pNode->next_sibling_);
+
+ if (prev->next_sibling_)
+ prev->next_sibling_->prev_sibling_ = prev;
}
if (last_child_.Get() == pNode)
last_child_ = pNode->prev_sibling_.Get();
- if (pNode->next_sibling_)
- pNode->next_sibling_->prev_sibling_ = pNode->prev_sibling_;
-
pNode->parent_ = nullptr;
pNode->prev_sibling_ = nullptr;
}