You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@locus.apache.org on 2000/06/14 23:08:09 UTC

cvs commit: xml-xerces/c/src/dom DOM_Node.cpp ElementImpl.cpp

andyh       00/06/14 14:08:08

  Modified:    c/src/dom DOM_Node.cpp ElementImpl.cpp
  Log:
  DOM attribute/named nodemaps: Fix a couple of null ptr problems.
  Joe Polastre.
  
  Revision  Changes    Path
  1.7       +8 -1      xml-xerces/c/src/dom/DOM_Node.cpp
  
  Index: DOM_Node.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/DOM_Node.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DOM_Node.cpp	2000/06/07 22:49:40	1.6
  +++ DOM_Node.cpp	2000/06/14 21:08:07	1.7
  @@ -56,6 +56,10 @@
   
   /*
    * $Log: DOM_Node.cpp,v $
  + * Revision 1.7  2000/06/14 21:08:07  andyh
  + * DOM attribute/named nodemaps: Fix a couple of null ptr problems.
  + * Joe Polastre.
  + *
    * Revision 1.6  2000/06/07 22:49:40  andyh
    * Memory usage reduction:  DOM NamedNodeMaps for attributes are allocated
    * only for elements that actually have attributes.  By Joe Polastre.
  @@ -243,7 +247,10 @@
     
   DOM_NamedNodeMap DOM_Node::getAttributes() const
   {
  -    return (fImpl->getAttributes() == null) ? DOM_NamedNodeMap(fImpl) : DOM_NamedNodeMap(fImpl->getAttributes());
  +	if (getNodeType() == ELEMENT_NODE)
  +		return (fImpl->getAttributes() == null) ? DOM_NamedNodeMap(fImpl) : DOM_NamedNodeMap(fImpl->getAttributes());
  +	else
  +		return DOM_NamedNodeMap();
   };
   
     
  
  
  
  1.23      +41 -28    xml-xerces/c/src/dom/ElementImpl.cpp
  
  Index: ElementImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/ElementImpl.cpp,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ElementImpl.cpp	2000/06/07 22:49:41	1.22
  +++ ElementImpl.cpp	2000/06/14 21:08:07	1.23
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: ElementImpl.cpp,v 1.22 2000/06/07 22:49:41 andyh Exp $
  + * $Id: ElementImpl.cpp,v 1.23 2000/06/14 21:08:07 andyh Exp $
    */
   
   #include "DeepNodeListImpl.hpp"
  @@ -129,7 +129,11 @@
   DOMString ElementImpl::getAttribute(const DOMString &nam)
   {
       static DOMString *emptyString = 0;
  -    AttrImpl * attr=(AttrImpl *)(attributes->getNamedItem(nam));
  +    AttrImpl * attr=null;
  +
  +    if (attributes != null)
  +	attr=(AttrImpl *)(attributes->getNamedItem(nam));
  +
       return (attr==null) ? DStringPool::getStaticString("", &emptyString) : attr->getValue();
   };
   
  @@ -171,14 +175,17 @@
       if (readOnly())
           throw DOM_DOMException(
           DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -    
  -    AttrImpl *att = (AttrImpl *) attributes->getNamedItem(nam);
  -    // Remove it
  -    if (att != null)
  -    {
  -        attributes->removeNamedItem(nam);
  -        if (att->nodeRefCount == 0)
  -            NodeImpl::deleteIf(att);
  +
  +    if (attributes != null)
  +    {    
  +    	AttrImpl *att = (AttrImpl *) attributes->getNamedItem(nam);
  +    	// Remove it
  +    	if (att != null)
  +    	{
  +    	    attributes->removeNamedItem(nam);
  +    	    if (att->nodeRefCount == 0)
  +    	        NodeImpl::deleteIf(att);
  +    	}
       }
   };
   
  @@ -190,17 +197,20 @@
           throw DOM_DOMException(
           DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
       
  -    AttrImpl *found = (AttrImpl *) attributes->getNamedItem(oldAttr->getName());
  +    if (attributes != null)
  +    {
  +	    AttrImpl *found = (AttrImpl *) attributes->getNamedItem(oldAttr->getName());
       
  -    // If it is in fact the right object, remove it.
  +	    // If it is in fact the right object, remove it.
       
  -    if (found == oldAttr)
  -    {
  -        attributes->removeNamedItem(oldAttr->getName());
  -        return found;
  -    }
  -    else
  -        throw DOM_DOMException(DOM_DOMException::NOT_FOUND_ERR, null);
  +	    if (found == oldAttr)
  +	    {
  +	        attributes->removeNamedItem(oldAttr->getName());
  +	        return found;
  +	    }
  +	    else
  +	        throw DOM_DOMException(DOM_DOMException::NOT_FOUND_ERR, null);
  +	}
   	return null;	// just to keep the compiler happy
   };
   
  @@ -310,15 +320,18 @@
       if (readOnly())
           throw DOM_DOMException(
   	    DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -    
  -    AttrImpl *att =
  -      (AttrImpl *) attributes->getNamedItemNS(fNamespaceURI, fLocalName);
  -    // Remove it 
  -    if (att != null) {
  -        attributes->removeNamedItemNS(fNamespaceURI, fLocalName);
  -        if (att->nodeRefCount == 0)
  -            NodeImpl::deleteIf(att);
  -    }
  + 
  +    if (attributes != null)
  +    {   
  +		AttrImpl *att =
  +		  (AttrImpl *) attributes->getNamedItemNS(fNamespaceURI, fLocalName);
  +		// Remove it 
  +		if (att != null) {
  +			attributes->removeNamedItemNS(fNamespaceURI, fLocalName);
  +			if (att->nodeRefCount == 0)
  +				NodeImpl::deleteIf(att);
  +		}
  +	}
   }