diff --git a/src/xercesc/util/XMLString.cpp b/src/xercesc/util/XMLString.cpp index cc87784ce93cceb0fca7248ca80c865b6693b702..82a3d1c08681955670395e84a9901c9c0507ea2b 100644 --- a/src/xercesc/util/XMLString.cpp +++ b/src/xercesc/util/XMLString.cpp @@ -592,25 +592,21 @@ void XMLString::trim(char* const toTrim) void XMLString::subString(char* const targetStr, const char* const srcStr , const int startIndex, const int endIndex) { - //if (startIndex < 0 || endIndex < 0) - // ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Str_NegativeIndex); - - if (targetStr == 0) + if (targetStr == 0) ThrowXML(IllegalArgumentException, XMLExcepts::Str_ZeroSizedTargetBuf); const int srcLen = strlen(srcStr); - const int copySize = endIndex - startIndex; + const int copySize = endIndex - startIndex; // Make sure the start index is within the XMLString bounds - if (startIndex > srcLen-1 || endIndex > srcLen ) + if ( startIndex < 0 || startIndex > endIndex || endIndex > srcLen) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Str_StartIndexPastEnd); - for (int i= startIndex; i < endIndex; i++) { - - targetStr[i-startIndex] = srcStr[i]; - } + for (int i= startIndex; i < endIndex; i++) { + targetStr[i-startIndex] = srcStr[i]; + } - targetStr[copySize] = 0; + targetStr[copySize] = 0; } /** @@ -1450,25 +1446,24 @@ void XMLString::lowerCase(XMLCh* const toLowerCase) void XMLString::subString(XMLCh* const targetStr, const XMLCh* const srcStr , const int startIndex, const int endIndex) { - //if (startIndex < 0 || endIndex < 0) + //if (startIndex < 0 || endIndex < 0) // ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Str_NegativeIndex); - if (targetStr == 0) + if (targetStr == 0) ThrowXML(IllegalArgumentException, XMLExcepts::Str_ZeroSizedTargetBuf); const int srcLen = stringLen(srcStr); - const int copySize = endIndex - startIndex; + const int copySize = endIndex - startIndex; // Make sure the start index is within the XMLString bounds - if (startIndex > srcLen-1 || endIndex > srcLen ) + if ( startIndex < 0 || startIndex > endIndex || endIndex > srcLen) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Str_StartIndexPastEnd); - for (int i= startIndex; i < endIndex; i++) { - - targetStr[i-startIndex] = srcStr[i]; - } + for (int i= startIndex; i < endIndex; i++) { + targetStr[i-startIndex] = srcStr[i]; + } - targetStr[copySize] = 0; + targetStr[copySize] = 0; } RefVectorOf<XMLCh>* XMLString::tokenizeString(const XMLCh* const tokenizeSrc) diff --git a/src/xercesc/util/XMLUri.cpp b/src/xercesc/util/XMLUri.cpp index ec71810c155169c4b9de2cfc977d56c591ad4892..196674bbc74fc5a813196de24766350579ec316e 100644 --- a/src/xercesc/util/XMLUri.cpp +++ b/src/xercesc/util/XMLUri.cpp @@ -376,6 +376,14 @@ void XMLUri::initialize(const XMLUri* const baseURI index = XMLString::stringLen(fScheme)+1; } + // It's an error if we stop here + if (index == trimedUriSpecLen) + { + ThrowXML1(NumberFormatException + , XMLExcepts::XMLNUM_URI_Component_Empty + , errMsg_PATH); + } + // two slashes means generic URI syntax, so we get the authority XMLCh* authUriSpec = new XMLCh[trimedUriSpecLen+1]; ArrayJanitor<XMLCh> authName(authUriSpec);