From ead0d4d6a08a4de642d8d4372bf0b7451f710640 Mon Sep 17 00:00:00 2001
From: Tinny Ng <tng@apache.org>
Date: Tue, 10 Jul 2001 16:13:05 +0000
Subject: [PATCH] Fix null pointer check in Standalone check.

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@172863 13f79535-47bb-0310-9956-ffa450edef68
---
 src/internal/XMLScanner2.cpp | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/internal/XMLScanner2.cpp b/src/internal/XMLScanner2.cpp
index 008672ed3..285df72a2 100644
--- a/src/internal/XMLScanner2.cpp
+++ b/src/internal/XMLScanner2.cpp
@@ -566,8 +566,12 @@ bool XMLScanner::normalizeAttValue( const   XMLCh* const        attrName
     // Get attribute def - to check to see if it's declared externally or not
     //
     bool  added = false;
-    const XMLAttDef* attDef = fElemStack.topElement()->fThisElement->findAttr(attrName, 0, 0, 0, XMLElementDecl::FailIfNotFound, added);
-    bool  isAttExternal = (attDef) ? attDef->isExternal() : false;
+    bool  isAttExternal = false;
+    const ElemStack::StackElem* topElem = fElemStack.topElement();
+    if (topElem && topElem->fThisElement) {
+        const XMLAttDef* attDef = topElem->fThisElement->findAttr(attrName, 0, 0, 0, XMLElementDecl::FailIfNotFound, added);
+        isAttExternal = (attDef) ? attDef->isExternal() : false;
+    }
 
     //
     //  Loop through the chars of the source value and normalize it according
@@ -610,7 +614,7 @@ bool XMLScanner::normalizeAttValue( const   XMLCh* const        attrName
                     // Check Validity Constraint for Standalone document declaration
                     // XML 1.0, Section 2.9
                     //
-                    if (fValidate && fStandalone && isAttExternal)
+                    if (fStandalone && fValidate && isAttExternal)
                     {
                          //
                          // Can't have a standalone document declaration of "yes" if  attribute
@@ -639,7 +643,7 @@ bool XMLScanner::normalizeAttValue( const   XMLCh* const        attrName
                     // Check Validity Constraint for Standalone document declaration
                     // XML 1.0, Section 2.9
                     //
-                    if (fValidate && fStandalone && isAttExternal)
+                    if (fStandalone && fValidate && isAttExternal)
                     {
                          //
                          // Can't have a standalone document declaration of "yes" if  attribute
@@ -663,7 +667,7 @@ bool XMLScanner::normalizeAttValue( const   XMLCh* const        attrName
                         // Check Validity Constraint for Standalone document declaration
                         // XML 1.0, Section 2.9
                         //
-                        if (fValidate && fStandalone && isAttExternal)
+                        if (fStandalone && fValidate && isAttExternal)
                         {
                              //
                              // Can't have a standalone document declaration of "yes" if  attribute
@@ -1591,8 +1595,12 @@ bool XMLScanner::scanAttValue(  const   XMLCh* const        attrName
     // Get attribute def - to check to see if it's declared externally or not
     //
     bool  added = false;
-    const XMLAttDef* attDef = fElemStack.topElement()->fThisElement->findAttr(attrName, 0, 0, 0, XMLElementDecl::FailIfNotFound, added);
-    bool  isAttExternal = (attDef) ? attDef->isExternal() : false;
+    bool  isAttExternal = false;
+    const ElemStack::StackElem* topElem = fElemStack.topElement();
+    if (topElem && topElem->fThisElement) {
+        const XMLAttDef* attDef = topElem->fThisElement->findAttr(attrName, 0, 0, 0, XMLElementDecl::FailIfNotFound, added);
+        isAttExternal = (attDef) ? attDef->isExternal() : false;
+    }
 
     //
     //  Loop until we get the attribute value. Note that we use a double
@@ -1732,7 +1740,7 @@ bool XMLScanner::scanAttValue(  const   XMLCh* const        attrName
                         // Check Validity Constraint for Standalone document declaration
                         // XML 1.0, Section 2.9
                         //
-                        if (fValidate && fStandalone && isAttExternal)
+                        if (fStandalone && fValidate && isAttExternal)
                         {
                              //
                              // Can't have a standalone document declaration of "yes" if  attribute
@@ -1761,7 +1769,7 @@ bool XMLScanner::scanAttValue(  const   XMLCh* const        attrName
                         // Check Validity Constraint for Standalone document declaration
                         // XML 1.0, Section 2.9
                         //
-                        if (fValidate && fStandalone && isAttExternal)
+                        if (fStandalone && fValidate && isAttExternal)
                         {
                              //
                              // Can't have a standalone document declaration of "yes" if  attribute
@@ -1783,7 +1791,7 @@ bool XMLScanner::scanAttValue(  const   XMLCh* const        attrName
                             // Check Validity Constraint for Standalone document declaration
                             // XML 1.0, Section 2.9
                             //
-                            if (fValidate && fStandalone && isAttExternal)
+                            if (fStandalone && fValidate && isAttExternal)
                             {
                                  //
                                  // Can't have a standalone document declaration of "yes" if  attribute
-- 
GitLab