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 Daniele Carlucci <da...@email.it> on 2004/07/08 12:29:58 UTC

Segmentation Fault

Hi,
I write the part of SAX code:

void MyProject::startElement(const   XMLCh* const    name
                                    ,       AttributeList&  attributes)
{
int r;
int pippo=atoi(XTOC(attributes.getValue("Value")));

cout << pippo;


The output code is:
<?xml version="1.0" encoding="LATIN1"?>
Segmentation fault

What can I do to solve it?

Thanks
Daniele


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


Re: Segmentation Fault

Posted by Alberto Massari <am...@progress.com>.
At 12.29 08/07/2004 +0200, Daniele Carlucci wrote:
>Hi,
>I write the part of SAX code:
>
>void MyProject::startElement(const   XMLCh* const    name
>                                    ,       AttributeList&  attributes)
>{
>int r;
>int pippo=atoi(XTOC(attributes.getValue("Value")));
>
>cout << pippo;

Daniele,
startElement is called every time an XML element is found in the file; you 
are not checking what the "name" is, and expect that a "Value" attribute is 
there. So, unless all of the elements in the file have a "Value" attribute, 
you will get a NULL pointer and try to run XTOC on it, and you will get the 
segmentation fault.
A more robust code would be

{
         if(XMLString::equals(name,g_theElementIamLookingFor))
         {
                 const XMLCh* value=attributes.getValue("Value");
                 if(value)
                         cout << atoi(XTOC(value));
         }
}

Alberto


>The output code is:
><?xml version="1.0" encoding="LATIN1"?>
>Segmentation fault
>
>What can I do to solve it?
>
>Thanks
>Daniele
>
>
>---------------------------------------------------------------------
>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