Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Xerces segmentation fault

Reply
Thread Tools

Xerces segmentation fault

 
 
mearvk
Guest
Posts: n/a
 
      02-09-2008
Running this on Redhat I get a segmentation fault in parseResultData's
for-loop during its second iteration. Anything obviously wrong with my
code?

Thanks.


[CODE main.C ]

#include <string>
#include <iostream>
#include "DDAS_XML_Handler.hpp"

extern "C"
{
#include "lip.h"
}

using namespace std;

int main()
{
DDAS_XML_Handler* handler=new DDAS_XML_Handler();

DDAS_VALIDATION_STRUCT result = handler-
>parseResultData( "result.xml" );


for(unsigned int i=0; i<result.size; i++)
{
cout<<"Result #";
zwrite(result.def_nums[i]);
cout<<" has SSE: "<<result.SSEs[i]<<endl;
}
}

[/CODE]

[CODE DDAS_XML_Handler.C (partial)]

//parse xml document containing boinc result data
DDAS_VALIDATION_STRUCT DDAS_XML_Handler:arseResultData(const
char* file_path)
{
DDAS_VALIDATION_STRUCT retval;

DOMAttr* sse_attr;
DOMAttr* def_num_attr;
DOMDocument* doc;
DOMNodeList* data_rows;
DOMElement* current;

XercesDOMParser* parser;

try
{
XMLCh* data_row_xmlch =
XMLString::transcode("data_row");
XMLCh* sse_xmlch =
XMLString::transcode("SSE");
XMLCh* def_num_xmlch =
XMLString::transcode("definition_number");

parser = new XercesDOMParser();
parser-
>setValidationScheme(XercesDOMParser::Val_Always );

parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);
parser->parse(file_path);

doc = parser->getDocument();
data_rows = doc-
>getElementsByTagName(data_row_xmlch);


retval.size = data_rows->getLength();
retval.SSEs = new double[ retval.size ];
retval.def_nums = new verylong[ retval.size ];

for(unsigned int i=0; i<retval.size; i++)
{
//current data_row
current =
dynamic_cast<DOMElement*> (data_rows->item(i));

//get current's attribute nodes
sse_attr = current-
>getAttributeNode( sse_xmlch );

def_num_attr = current-
>getAttributeNode( def_num_xmlch );


//convert attribute values from XMLCh*
to char*
char* sse_ch = new
char[128];
char* def_num_ch = new
char[128];
sse_ch =
XMLString::transcode( sse_attr->getValue() );
def_num_ch =
XMLString::transcode( def_num_attr->getValue() );

//convert from char* to numeric
representation
retval.SSEs[i] =
atof( sse_ch );
zsread( def_num_ch ,
&retval.def_nums[i] );

//free dynamic memory
free(sse_ch);
free(def_num_ch);
}
}
catch( xercesc::XMLException& e)
{
char* message =
XMLString::transcode( e.getMessage() );
cout << "Error parsing XML document: " <<
message << endl;
XMLString::release( &message );
}

return retval;

[/CODE]

[CODE DDAS_XML_Handler.hpp]

extern "C"
{
#include "lip.h"
}

struct DDAS_VALIDATION_STRUCT
{
double* SSEs;
unsigned int size;
verylong* def_nums;
};


class DDAS_XML_Handler
{
private:
// char* URL;

public:
//constructor
DDAS_XML_Handler();

//destructor
~DDAS_XML_Handler();

//returns a node list given a URL and a node name
//xercesc:OMNodeList* getNodeList(char* node_name);

//converts client's result data from XML file to form
appropriate for validation
DDAS_VALIDATION_STRUCT
DDAS_XML_Handler:arseResultData(const char* file_path);


//prints all matching attributes from a DOMNodeList
//void printNodeListAttrs(xercesc:OMNodeList*
node_list, char* node_attr);

//prints matching attribute for a given DOMNode
//void printNodeAttr(xercesc:OMNode* node, char*
node_attr);
};

[/CODE]


[DATA result.xml ]


<DDAS_result_set>

<data_row SSE="138.328873" binary="11101101"
definition_number="237">
<regression_coefficient id="7" value="0.023954"/>
<regression_coefficient id="6" value="0.003977"/>
<regression_coefficient id="5" value="-0.004866"/>
<regression_coefficient id="3" value="0.000086"/>
<regression_coefficient id="2" value="0.004871"/>
<regression_coefficient id="0" value="-0.000803"/>
</data_row>

<data_row SSE="137.649657" binary="11110110"
definition_number="246">
<regression_coefficient id="7" value="0.022691"/>
<regression_coefficient id="6" value="0.003805"/>
<regression_coefficient id="5" value="-0.005100"/>
<regression_coefficient id="4" value="0.000317"/>
<regression_coefficient id="2" value="0.003974"/>
<regression_coefficient id="1" value="0.096372"/>
</data_row>

<data_row SSE="137.549310" binary="11101111"
definition_number="239">
<regression_coefficient id="7" value="0.024656"/>
<regression_coefficient id="6" value="0.003862"/>
<regression_coefficient id="5" value="-0.004905"/>
<regression_coefficient id="3" value="0.000051"/>
<regression_coefficient id="2" value="0.004222"/>
<regression_coefficient id="1" value="0.098256"/>
<regression_coefficient id="0" value="-0.001051"/>
</data_row>

<data_row SSE="137.628296" binary="11101110"
definition_number="238">
<regression_coefficient id="7" value="0.022820"/>
<regression_coefficient id="6" value="0.003741"/>
<regression_coefficient id="5" value="-0.005057"/>
<regression_coefficient id="3" value="0.000065"/>
<regression_coefficient id="2" value="0.004152"/>
<regression_coefficient id="1" value="0.095907"/>
</data_row>

<data_row SSE="137.665670" binary="11100110"
definition_number="230">
<regression_coefficient id="7" value="0.022538"/>
<regression_coefficient id="6" value="0.003791"/>
<regression_coefficient id="5" value="-0.005077"/>
<regression_coefficient id="2" value="0.004172"/>
<regression_coefficient id="1" value="0.098258"/>
</data_row>

<data_row SSE="137.572043" binary="11100111"
definition_number="231">
<regression_coefficient id="7" value="0.024580"/>
<regression_coefficient id="6" value="0.003910"/>
<regression_coefficient id="5" value="-0.004909"/>
<regression_coefficient id="2" value="0.004243"/>
<regression_coefficient id="1" value="0.100252"/>
<regression_coefficient id="0" value="-0.001132"/>
</data_row>

<data_row SSE="138.316077" binary="11111101"
definition_number="253">
<regression_coefficient id="7" value="0.023960"/>
<regression_coefficient id="6" value="0.003998"/>
<regression_coefficient id="5" value="-0.004901"/>
<regression_coefficient id="4" value="0.000313"/>
<regression_coefficient id="3" value="0.000069"/>
<regression_coefficient id="2" value="0.004669"/>
<regression_coefficient id="0" value="-0.000762"/>
</data_row>

<data_row SSE="138.342605" binary="11111011"
definition_number="251">
<regression_coefficient id="7" value="0.024320"/>
<regression_coefficient id="6" value="0.004323"/>
<regression_coefficient id="5" value="-0.004240"/>
<regression_coefficient id="4" value="0.000961"/>
<regression_coefficient id="3" value="0.000008"/>
<regression_coefficient id="1" value="0.109715"/>
<regression_coefficient id="0" value="-0.000738"/>
</data_row>

<data_row SSE="137.565598" binary="11110111"
definition_number="247">
<regression_coefficient id="7" value="0.024595"/>
<regression_coefficient id="6" value="0.003914"/>
<regression_coefficient id="5" value="-0.004930"/>
<regression_coefficient id="4" value="0.000204"/>
<regression_coefficient id="2" value="0.004113"/>
<regression_coefficient id="1" value="0.098959"/>
<regression_coefficient id="0" value="-0.001086"/>
</data_row>

<data_row SSE="137.625804" binary="11111110"
definition_number="254">
<regression_coefficient id="7" value="0.022853"/>
<regression_coefficient id="6" value="0.003753"/>
<regression_coefficient id="5" value="-0.005070"/>
<regression_coefficient id="4" value="0.000138"/>
<regression_coefficient id="3" value="0.000057"/>
<regression_coefficient id="2" value="0.004068"/>
<regression_coefficient id="1" value="0.095368"/>
</data_row>

</DDAS_result_set>

[/DATA]
 
Reply With Quote
 
 
 
 
P. Lepin
Guest
Posts: n/a
 
      02-10-2008

mearvk wrote:
> Running this on Redhat I get a segmentation fault in parseResultData's
> for-loop during its second iteration. Anything obviously wrong with my
> code?


[code]

Obviously wrong. If you want help on Usenet, invest some effort into making
your code readable to others (do not use tabs for indentation, make sure
your code is formatted to fit 78 chars).

> char* sse_ch = new
> char[128];
> char* def_num_ch = new
> char[128];
> sse_ch =
> XMLString::transcode( sse_attr->getValue() );
> def_num_ch =
> XMLString::transcode( def_num_attr->getValue() );


Obviously wrong. XML spec does not guarantee an atrribute's value will fit
in 128 octets.

> free(sse_ch);
> free(def_num_ch);


Obviously wrong. See

<http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.3>

After this I didn't bother to look at it in greater detail. If you want a
thorough grilling, you can always submit yourself to the Great Old Ones of
comp.lang.c++ (note that they are only interested in issues relevant to
ISO/ANSI Standard C++; questions relevant only to specific platforms and/or
libraries will not be welcome).

--
Presented in Brain Control where available.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault using Firefox 15.0.2 Keith Lee Firefox 3 04-29-2006 05:45 PM
Xerces on Solaris - Segmentation fault ldvmbs@gmail.com XML 0 05-16-2005 07:21 AM
Upgrade of Xalan 1.2.2 and Xerces 1.4.4 to Xalan 2.6 and Xerces 2.6.2 cvissy XML 0 11-16-2004 07:06 AM
Xerces XML Parser Segmentation fault with Java Pud XML 0 11-06-2003 05:07 PM
Intel Xeon + Linux + IBM sdk 1.3.1 - getting Segmentation fault Alex Hunsley Java 17 11-06-2003 12:12 AM



Advertisments