amassari 2004/09/30 06:14:28 Modified: c/src/xercesc/validators/DTD DTDScanner.cpp c/src/xercesc/validators/schema GeneralAttributeCheck.cpp SchemaValidator.cpp TraverseSchema.cpp Log: Fix jira#1280 - Borland leaks memory if break or continue are used inside a catch block Revision Changes Path 1.35 +139 -133 xml-xerces/c/src/xercesc/validators/DTD/DTDScanner.cpp Index: DTDScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/DTD/DTDScanner.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- DTDScanner.cpp 8 Sep 2004 13:56:50 -0000 1.34 +++ DTDScanner.cpp 30 Sep 2004 13:14:27 -0000 1.35 @@ -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,168 +2659,171 @@ 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 1.24 +8 -1 xml-xerces/c/src/xercesc/validators/schema/GeneralAttributeCheck.cpp Index: GeneralAttributeCheck.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/GeneralAttributeCheck.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- GeneralAttributeCheck.cpp 29 Sep 2004 20:58:10 -0000 1.23 +++ GeneralAttributeCheck.cpp 30 Sep 2004 13:14:28 -0000 1.24 @@ -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 @@ 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 @@ schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AttributeDisallowed, attName, contextStr, elemName); - continue; + bContinue=true; } + if(bContinue) + continue; if (fgElemAttTable[elemContext][attNameId] & Att_Mask) { 1.58 +7 -1 xml-xerces/c/src/xercesc/validators/schema/SchemaValidator.cpp Index: SchemaValidator.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaValidator.cpp,v retrieving revision 1.57 retrieving revision 1.58 diff -u -r1.57 -r1.58 --- SchemaValidator.cpp 27 Sep 2004 20:13:59 -0000 1.57 +++ SchemaValidator.cpp 30 Sep 2004 13:14:28 -0000 1.58 @@ -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 @@ 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 @@ } catch(const XMLException&) { if (!toLax && baseNode->getMinTotalRange()) { - break; + bDoBreak=true; } } + if(bDoBreak) + break; } // did not find a match 1.122 +9 -3 xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp Index: TraverseSchema.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp,v retrieving revision 1.121 retrieving revision 1.122 diff -u -r1.121 -r1.122 --- TraverseSchema.cpp 30 Sep 2004 11:00:07 -0000 1.121 +++ TraverseSchema.cpp 30 Sep 2004 13:14:28 -0000 1.122 @@ -3058,6 +3058,7 @@ 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 @@ 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 @@ 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 @@ throw; } catch(...) { - break; + bDoBreak=true; } + if(bDoBreak) + break; if (content->getNodeType() == DOMNode::ELEMENT_NODE) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]