diff --git a/src/xercesc/internal/IGXMLScanner.cpp b/src/xercesc/internal/IGXMLScanner.cpp
index 2470eed9980b471bc3f8b2f2e1edceb2986f4b7b..97254cf7d45eb292d4b57fd05f063bcc3187c00a 100644
--- a/src/xercesc/internal/IGXMLScanner.cpp
+++ b/src/xercesc/internal/IGXMLScanner.cpp
@@ -1169,8 +1169,10 @@ void IGXMLScanner::scanEndTag(bool& gotData)
     if (fGrammarType == Grammar::SchemaGrammarType) {        
         if (!isRoot)
         {
-            // update error information
-            fErrorStack->push(fErrorStack->pop() || fPSVIElemContext.fErrorOccurred);
+            // update error information            
+            fErrorStack->push((fErrorStack->size() && fErrorStack->pop()) || fPSVIElemContext.fErrorOccurred);
+  
+
         }
     }
 
diff --git a/src/xercesc/internal/SGXMLScanner.cpp b/src/xercesc/internal/SGXMLScanner.cpp
index 7fd344c3ef2b61b2c20122182375f9ab59c0660b..a5c493e64a3efaa45e00b70c8c26afab9844c9f9 100644
--- a/src/xercesc/internal/SGXMLScanner.cpp
+++ b/src/xercesc/internal/SGXMLScanner.cpp
@@ -1025,7 +1025,7 @@ void SGXMLScanner::scanEndTag(bool& gotData)
     if (!isRoot)
     {
         // update error information
-        fErrorStack->push(fErrorStack->pop() || fPSVIElemContext.fErrorOccurred);
+        fErrorStack->push((fErrorStack->size() && fErrorStack->pop()) || fPSVIElemContext.fErrorOccurred);
     }
 
     // If this was the root, then done with content