Hi all, yeah, I'm a newbee here...

Maybe I'm doing something wrong or maybe it's just Friday afternoon and I want to go 
home, but I can't seem to find Xerces-C++ on the product list page to submit this bug 
to Bugzilla. I see Xerces-J and Xerces-P but no Xerces-C. :-(

Anyway...
I'm using xerces-c-2.2.0 on Win32 (XP Pro) with VC++6.0.

Passing in -1 as the value of 'count' to DOMCharacterData::substringData (), the 
documentation states a DOMException will be thrown. During testing of my code, instead 
of getting the expected exception, I get an access violation.

I tracked the problem to the following check in DOMCharacterDataImpl::substringData ():

    if (offset > len || offset < 0 || count < 0)
        throw DOMException(DOMException::INDEX_SIZE_ERR, 0);

Note that 'count' and 'offset' are type XMLSize_t which is typedef'd as 'unsigned 
long'. By the time this check is performed, 'count' is a very large integer. (count == 
-1) gets past this check and eventually leads to the access violation.

Casting 'count' to 'long' fixes this problem... well, makes it go away anyhow...

Also note, I believe that a negative 'offset' succeeds because of the (offset > len) 
check rather than (offset < 0).

Thanks, have a good weekend!
Dave.

example code:
#include <xercesc/dom/DOMCharacterData.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationRegistry.hpp>

#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <iostream>

XERCES_CPP_NAMESPACE_USE;

int testPT758 ()
{
   try
   {
      XMLPlatformUtils::Initialize();
      DOMImplementation* domImplementation = 
DOMImplementationRegistry::getDOMImplementation(NULL);
      
      XMLCh* tmp = XMLString::transcode ("test");
      DOMDocument* doc = domImplementation->createDocument(0, tmp, 0);
      XMLString::release (&tmp);
      
      tmp = XMLString::transcode ("test data");
      DOMCharacterData* ch= (DOMCharacterData*)doc->createTextNode (tmp);
      XMLString::release (&tmp);
      
      //const XMLCh* data = ch->substringData (0, 9);  // works fine
      //const XMLCh* data = ch->substringData (-1, 9); // throws DOMException as 
documented
      //const XMLCh* data = ch->substringData (10, 9); // throws DOMException as 
documented
      const XMLCh* data = ch->substringData (0, -1); // does not throw DOMException as 
documented
      
      char* pData = NULL; 
      pData = XMLString::transcode (data);
      std::cout << pData << std::endl;
      XMLString::release (&pData);
   }
   catch (const DOMException& e)
   {
      const unsigned int maxChars = 2047;
      XMLCh errText[maxChars + 1];
      if (DOMImplementation::loadDOMExceptionMsg( e.code, errText, maxChars))
      {
         char* pData = NULL; 
         pData = XMLString::transcode (errText);
         std::cout << pData << std::endl;
         XMLString::release (&pData);
      }
      else
      {
         std::cout << "DOMException" << std::endl; 
      }
   }
   catch (...)
   {
      std::cout << "unknown exception" << std::endl;
   }
   
   XMLPlatformUtils::Terminate();
   return 0;
}

*******************************************
* David J. Rager
* Software Engineer
* Concurrent Technologies Corporation (CTC)
* (814) 269-2548
* [EMAIL PROTECTED]
*
* Due to security issues with Outlook and
* Internet Explorer, all HTML formatting is
* stripped from email before it reaches my
* inbox.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to