From 96b0d1332430e34219334373aeb0f6a85eb8ad68 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 25 Jul 2018 17:04:49 +0000 Subject: Introduce ToXMLElement() checked downcast helper function And use it in place of ASSERT() that the type was correct. Since we can check it, doing so at runtime may help avoid type confusion, and we'll get a nice safe SEGV if the asserted condition ever fails. Change-Id: I46b65a4b70e819a670d7cad7966e0d100f0d9a63 Reviewed-on: https://pdfium-review.googlesource.com/38810 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- core/fxcrt/xml/cfx_xmlelement.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'core/fxcrt') diff --git a/core/fxcrt/xml/cfx_xmlelement.h b/core/fxcrt/xml/cfx_xmlelement.h index ca5fd5e797..0d3468aba4 100644 --- a/core/fxcrt/xml/cfx_xmlelement.h +++ b/core/fxcrt/xml/cfx_xmlelement.h @@ -54,4 +54,10 @@ class CFX_XMLElement : public CFX_XMLNode { std::map attrs_; }; +inline CFX_XMLElement* ToXMLElement(CFX_XMLNode* pNode) { + return pNode && pNode->GetType() == FX_XMLNODE_Element + ? static_cast(pNode) + : nullptr; +} + #endif // CORE_FXCRT_XML_CFX_XMLELEMENT_H_ -- cgit v1.2.3