From 92c68c36eb0a19a28a7edec334876a90b315d04f Mon Sep 17 00:00:00 2001
From: David Abram Cargill <cargilld@apache.org>
Date: Mon, 20 Dec 2004 15:50:42 +0000
Subject: [PATCH] Add assert to avoid memory violation.

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

diff --git a/src/xercesc/internal/XMLReader.cpp b/src/xercesc/internal/XMLReader.cpp
index 7f493df3f..f621df8db 100644
--- a/src/xercesc/internal/XMLReader.cpp
+++ b/src/xercesc/internal/XMLReader.cpp
@@ -597,6 +597,9 @@ bool XMLReader::getName(XMLBuffer& toFill, const bool token)
     if (!token)
     {
         if (fXMLVersion == XMLV1_1 && ((fCharBuf[fCharIndex] >= 0xD800) && (fCharBuf[fCharIndex] <= 0xDB7F))) {
+           // make sure one more char is in the buffer, the transcoder
+           // should put only a complete surrogate pair into the buffer
+           assert(fCharIndex+1 < fCharsAvail);
            if ((fCharBuf[fCharIndex+1] < 0xDC00) || (fCharBuf[fCharIndex+1] > 0xDFFF))
                return false;
 
@@ -626,8 +629,11 @@ bool XMLReader::getName(XMLBuffer& toFill, const bool token)
             //  Check the current char and take it if its a name char. Else
             //  break out.
             if (fXMLVersion == XMLV1_1 && ((fCharBuf[fCharIndex] >= 0xD800) && (fCharBuf[fCharIndex] <= 0xDB7F))) {
-               if ((fCharBuf[fCharIndex+1] < 0xDC00) || (fCharBuf[fCharIndex+1] > 0xDFFF))
-                   return !toFill.isEmpty();
+                // make sure one more char is in the buffer, the transcoder
+                // should put only a complete surrogate pair into the buffer
+                assert(fCharIndex+1 < fCharsAvail);
+                if ((fCharBuf[fCharIndex+1] < 0xDC00) || (fCharBuf[fCharIndex+1] > 0xDFFF))
+                    return !toFill.isEmpty();
 
                 toFill.append(fCharBuf[fCharIndex++]);
                 fCurCol++;
-- 
GitLab