diff --git a/src/xercesc/validators/DTD/DTDScanner.cpp b/src/xercesc/validators/DTD/DTDScanner.cpp index 7f567a92146d2265072be46e4966d93e8bb556fb..d5f44b6db694e4a634a0aa349a3a7ef4b0e7ea05 100644 --- a/src/xercesc/validators/DTD/DTDScanner.cpp +++ b/src/xercesc/validators/DTD/DTDScanner.cpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.35 2004/09/30 13:14:27 amassari + * Fix jira#1280 - Borland leaks memory if break or continue are used inside a catch block + * * Revision 1.34 2004/09/08 13:56:50 peiyongz * Apache License Version 2.0 * @@ -2656,169 +2659,172 @@ void DTDScanner::scanExtSubsetDecl(const bool inIncludeSect, const bool isDTD) bool inCharData = false; while (true) { - try - { - while (true) + bool bDoBreak=false; // workaround for Borland bug with 'break' in 'catch' + try { - const XMLCh nextCh = fReaderMgr->peekNextChar(); - - if (nextCh == chOpenAngle) + while (true) { - // Get the reader we started this on - // XML 1.0 P28a Well-formedness constraint: PE Between Declarations - const unsigned int orgReader = fReaderMgr->getCurrentReaderNum(); - bool wasInPE = (fReaderMgr->getCurrentReader()->getType() == XMLReader::Type_PE); + const XMLCh nextCh = fReaderMgr->peekNextChar(); - // - // Now scan the markup. Set the flag so that we will know that - // we were in markup if an end of entity exception occurs. - // - fReaderMgr->getNextChar(); - inMarkup = true; - scanMarkupDecl(bAcceptDecl); - inMarkup = false; + if (nextCh == chOpenAngle) + { + // Get the reader we started this on + // XML 1.0 P28a Well-formedness constraint: PE Between Declarations + const unsigned int orgReader = fReaderMgr->getCurrentReaderNum(); + bool wasInPE = (fReaderMgr->getCurrentReader()->getType() == XMLReader::Type_PE); - // - // And see if we got back to the same level. If not, then its - // a partial markup error. - // - if (fReaderMgr->getCurrentReaderNum() != orgReader){ - if (wasInPE) - fScanner->emitError(XMLErrs::PEBetweenDecl); - else if (fScanner->getDoValidation()) - fScanner->getValidator()->emitError(XMLValid::PartialMarkupInPE); - } + // + // Now scan the markup. Set the flag so that we will know that + // we were in markup if an end of entity exception occurs. + // + fReaderMgr->getNextChar(); + inMarkup = true; + scanMarkupDecl(bAcceptDecl); + inMarkup = false; - } - else if (fReaderMgr->getCurrentReader()->isWhitespace(nextCh)) - { - // - // If we have a doc type handler, and advanced callbacks are - // enabled, then gather up whitespace and call back. Otherwise - // just skip whitespaces. - // - if (fDocTypeHandler) - { - inCharData = true; - fReaderMgr->getSpaces(bbSpace.getBuffer()); - inCharData = false; + // + // And see if we got back to the same level. If not, then its + // a partial markup error. + // + if (fReaderMgr->getCurrentReaderNum() != orgReader){ + if (wasInPE) + fScanner->emitError(XMLErrs::PEBetweenDecl); + else if (fScanner->getDoValidation()) + fScanner->getValidator()->emitError(XMLValid::PartialMarkupInPE); + } - fDocTypeHandler->doctypeWhitespace - ( - bbSpace.getRawBuffer() - , bbSpace.getLen() - ); } - else + else if (fReaderMgr->getCurrentReader()->isWhitespace(nextCh)) { // - // If we hit an end of entity in the middle of white - // space, that's fine. We'll just come back in here - // again on the next round and skip some more. + // If we have a doc type handler, and advanced callbacks are + // enabled, then gather up whitespace and call back. Otherwise + // just skip whitespaces. // - fReaderMgr->skipPastSpaces(); + if (fDocTypeHandler) + { + inCharData = true; + fReaderMgr->getSpaces(bbSpace.getBuffer()); + inCharData = false; + + fDocTypeHandler->doctypeWhitespace + ( + bbSpace.getRawBuffer() + , bbSpace.getLen() + ); + } + else + { + // + // If we hit an end of entity in the middle of white + // space, that's fine. We'll just come back in here + // again on the next round and skip some more. + // + fReaderMgr->skipPastSpaces(); + } } - } - else if (nextCh == chPercent) - { - // - // Expand (and scan if external) the reference value. Tell - // it to throw an end of entity exception at the end of the - // entity. - // - fReaderMgr->getNextChar(); - expandPERef(true, false, false, true); - } - else if (inIncludeSect && (nextCh == chCloseSquare)) - { - // - // Its the end of a conditional include section. So scan it and - // decrement the include depth counter. - // - fReaderMgr->getNextChar(); - if (!fReaderMgr->skippedChar(chCloseSquare)) + else if (nextCh == chPercent) { - fScanner->emitError(XMLErrs::ExpectedEndOfConditional); - fReaderMgr->skipPastChar(chCloseAngle); + // + // Expand (and scan if external) the reference value. Tell + // it to throw an end of entity exception at the end of the + // entity. + // + fReaderMgr->getNextChar(); + expandPERef(true, false, false, true); } - else if (!fReaderMgr->skippedChar(chCloseAngle)) + else if (inIncludeSect && (nextCh == chCloseSquare)) { - fScanner->emitError(XMLErrs::ExpectedEndOfConditional); - fReaderMgr->skipPastChar(chCloseAngle); + // + // Its the end of a conditional include section. So scan it and + // decrement the include depth counter. + // + fReaderMgr->getNextChar(); + if (!fReaderMgr->skippedChar(chCloseSquare)) + { + fScanner->emitError(XMLErrs::ExpectedEndOfConditional); + fReaderMgr->skipPastChar(chCloseAngle); + } + else if (!fReaderMgr->skippedChar(chCloseAngle)) + { + fScanner->emitError(XMLErrs::ExpectedEndOfConditional); + fReaderMgr->skipPastChar(chCloseAngle); + } + return; } - return; - } - else if (!nextCh) - { - return; // nothing left - } - else - { - fReaderMgr->getNextChar(); - if (!fReaderMgr->getCurrentReader()->isXMLChar(nextCh)) + else if (!nextCh) { - XMLCh tmpBuf[9]; - XMLString::binToText - ( - nextCh - , tmpBuf - , 8 - , 16 - , fMemoryManager - ); - fScanner->emitError(XMLErrs::InvalidCharacter, tmpBuf); + return; // nothing left } else { - fScanner->emitError(XMLErrs::InvalidDocumentStructure); - } + fReaderMgr->getNextChar(); + if (!fReaderMgr->getCurrentReader()->isXMLChar(nextCh)) + { + XMLCh tmpBuf[9]; + XMLString::binToText + ( + nextCh + , tmpBuf + , 8 + , 16 + , fMemoryManager + ); + fScanner->emitError(XMLErrs::InvalidCharacter, tmpBuf); + } + else + { + fScanner->emitError(XMLErrs::InvalidDocumentStructure); + } - // Try to get realigned - static const XMLCh toSkip[] = - { - chPercent, chCloseSquare, chOpenAngle, chNull - }; - fReaderMgr->skipUntilInOrWS(toSkip); + // Try to get realigned + static const XMLCh toSkip[] = + { + chPercent, chCloseSquare, chOpenAngle, chNull + }; + fReaderMgr->skipUntilInOrWS(toSkip); + } + bAcceptDecl = false; } - bAcceptDecl = false; } - } - catch(const EndOfEntityException& toCatch) - { - // - // If the external entity ended while we were in markup, then that's - // a partial markup error. - // - if (inMarkup) + catch(const EndOfEntityException& toCatch) { - fScanner->emitError(XMLErrs::PartialMarkupInEntity); - inMarkup = false; - } + // + // If the external entity ended while we were in markup, then that's + // a partial markup error. + // + if (inMarkup) + { + fScanner->emitError(XMLErrs::PartialMarkupInEntity); + inMarkup = false; + } - // If we were in char data, then send what we got - if (inCharData) - { - // Send what we got, then rethrow - if (fDocTypeHandler) + // If we were in char data, then send what we got + if (inCharData) { - fDocTypeHandler->doctypeWhitespace - ( - bbSpace.getRawBuffer() - , bbSpace.getLen() - ); + // Send what we got, then rethrow + if (fDocTypeHandler) + { + fDocTypeHandler->doctypeWhitespace + ( + bbSpace.getRawBuffer() + , bbSpace.getLen() + ); + } + inCharData = false; } - inCharData = false; - } - // - // If the entity that just ended was the entity that we started - // on, then this is the end of the external subset. - // - if (orgReader == toCatch.getReaderNum()) + // + // If the entity that just ended was the entity that we started + // on, then this is the end of the external subset. + // + if (orgReader == toCatch.getReaderNum()) + bDoBreak=true; + } + if(bDoBreak) break; } - } // If we have a doc type handler, tell it the ext subset ends if (fDocTypeHandler && isDTD) diff --git a/src/xercesc/validators/schema/GeneralAttributeCheck.cpp b/src/xercesc/validators/schema/GeneralAttributeCheck.cpp index 50de0b0140c21a28f3dcb488c5bf464501679e0e..86c5f2d8617dd322ba96a01a5183a6d150d1a336 100644 --- a/src/xercesc/validators/schema/GeneralAttributeCheck.cpp +++ b/src/xercesc/validators/schema/GeneralAttributeCheck.cpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.24 2004/09/30 13:14:28 amassari + * Fix jira#1280 - Borland leaks memory if break or continue are used inside a catch block + * * Revision 1.23 2004/09/29 20:58:10 knoaman * [Bug 1209] Problem with id usage across schema * http://issues.apache.org/jira/browse/XERCESC-1209 @@ -420,6 +423,7 @@ GeneralAttributeCheck::checkAttributes(const DOMElement* const elem, int attNameId = A_Invalid; attName = attribute->getLocalName(); + bool bContinue=false; // workaround for Borland bug with 'continue' in 'catch' try { attNameId= fAttMap->get(attName, fMemoryManager); } @@ -431,8 +435,10 @@ GeneralAttributeCheck::checkAttributes(const DOMElement* const elem, schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttributeDisallowed, attName, contextStr, elemName); - continue; + bContinue=true; } + if(bContinue) + continue; if (fgElemAttTable[elemContext][attNameId] & Att_Mask) { diff --git a/src/xercesc/validators/schema/SchemaValidator.cpp b/src/xercesc/validators/schema/SchemaValidator.cpp index a16869197538f89db91dc7b7950f6673c1f28dd2..c54599d7529c9a07bd5bfdb406f49519ec0fdcf6 100644 --- a/src/xercesc/validators/schema/SchemaValidator.cpp +++ b/src/xercesc/validators/schema/SchemaValidator.cpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.58 2004/09/30 13:14:28 amassari + * Fix jira#1280 - Borland leaks memory if break or continue are used inside a catch block + * * Revision 1.57 2004/09/27 20:13:59 knoaman * Reset datatype validator. * @@ -1899,6 +1902,7 @@ SchemaValidator::checkRecurse(SchemaGrammar* const currentGrammar, ContentSpecNode* baseNode = baseNodes->elementAt(j); current++; + bool bDoBreak=false; // workaround for Borland bug with 'break' in 'catch' try { checkParticleDerivationOk(currentGrammar, derivedNodes->elementAt(i), @@ -1908,9 +1912,11 @@ SchemaValidator::checkRecurse(SchemaGrammar* const currentGrammar, } catch(const XMLException&) { if (!toLax && baseNode->getMinTotalRange()) { - break; + bDoBreak=true; } } + if(bDoBreak) + break; } // did not find a match diff --git a/src/xercesc/validators/schema/TraverseSchema.cpp b/src/xercesc/validators/schema/TraverseSchema.cpp index 24020f1b2d14e4df741263efd752d2129cf78154..3a41c7bebc1dc15ba7f3904b11ac5f9fe5c98990 100644 --- a/src/xercesc/validators/schema/TraverseSchema.cpp +++ b/src/xercesc/validators/schema/TraverseSchema.cpp @@ -3058,6 +3058,7 @@ TraverseSchema::traverseByRestriction(const DOMElement* const rootElem, const XMLCh* facetName = content->getLocalName(); + bool bContinue=false; // workaround for Borland bug with 'continue' in 'catch' try { scope = fAttributeCheck.getFacetId(facetName, fMemoryManager); } @@ -3069,8 +3070,10 @@ TraverseSchema::traverseByRestriction(const DOMElement* const rootElem, reportSchemaError(content, XMLUni::fgXMLErrDomain, XMLErrs::InvalidFacetName, facetName); content = XUtil::getNextSiblingElement(content); - continue; + bContinue=true; } + if(bContinue) + continue; // REVISIT // check for annotation content - we are not checking whether the @@ -3608,6 +3611,7 @@ void TraverseSchema::traverseSimpleContentDecl(const XMLCh* const typeName, const XMLCh* facetName = content->getLocalName(); + bool bDoBreak=false; // workaround for Borland bug with 'break' in 'catch' // if not a valid facet, break from the loop try { scope = fAttributeCheck.getFacetId(facetName, fMemoryManager); @@ -3617,8 +3621,10 @@ void TraverseSchema::traverseSimpleContentDecl(const XMLCh* const typeName, throw; } catch(...) { - break; + bDoBreak=true; } + if(bDoBreak) + break; if (content->getNodeType() == DOMNode::ELEMENT_NODE) {