You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Jesse Pelton <js...@PKC.com> on 2004/06/28 21:17:48 UTC

XMLException default constructor is dangerous

I've just upgraded an application that used Xerces 2.0 to 2.5.  Our SAX
parser derives its own exception class from XMLException.  The default
XMLException constructor sets the memory manager to NULL, and the
XMLException destructor assumes it's not NULL and blindly calls
fMemoryManager->deallocate().  Other member functions (copy constructor,
operator=, setPosition(), and so on) make the same assumption, so the
only safe thing to do would seem to be to use the default memory manager
if the default constructor is called:

XMLException::XMLException() :

    fCode(XMLExcepts::NoError)
    , fSrcFile(0)
    , fSrcLine(0)
    , fMsg(0)
    , fMemoryManager(XMLPlatformUtils::fgMemoryManager)
{
}

It may be that deriving from XMLException is not a great idea.  I could
find no documentation to that effect, not do I recall any recommendation
against it in the 4+ years that I've been participating in the list.
Perhaps such a warning is in order.  In any case, I think making the
suggested change would be safe, cheap, and helpful.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: XMLException default constructor is dangerous

Posted by David Cargill <ca...@ca.ibm.com>.



I have made the change you suggested.

The other XMLException constructor (that takes arguments) tested if the
memory manager was null and set it to the default.

Regards,
David A. Cargill
XML Parser Development
IBM Toronto Lab
(905) 413-2371, tie 969
cargilld@ca.ibm.com


                                                                           
             "Jesse Pelton"                                                
             <js...@PKC.com>                                                 
                                                                        To 
             06/28/2004 03:17          <xe...@xml.apache.org>       
             PM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         XMLException default constructor is 
               xerces-c-dev            dangerous                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




I've just upgraded an application that used Xerces 2.0 to 2.5.  Our SAX
parser derives its own exception class from XMLException.  The default
XMLException constructor sets the memory manager to NULL, and the
XMLException destructor assumes it's not NULL and blindly calls
fMemoryManager->deallocate().  Other member functions (copy constructor,
operator=, setPosition(), and so on) make the same assumption, so the
only safe thing to do would seem to be to use the default memory manager
if the default constructor is called:

XMLException::XMLException() :

    fCode(XMLExcepts::NoError)
    , fSrcFile(0)
    , fSrcLine(0)
    , fMsg(0)
    , fMemoryManager(XMLPlatformUtils::fgMemoryManager)
{
}

It may be that deriving from XMLException is not a great idea.  I could
find no documentation to that effect, not do I recall any recommendation
against it in the 4+ years that I've been participating in the list.
Perhaps such a warning is in order.  In any case, I think making the
suggested change would be safe, cheap, and helpful.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org