Closed massimomorara closed 7 years ago
Parsing the following xml file with testlib
testlib
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <instance format="XCSP3" type="CSP"> <variables> <var id="x" as="y"/> </variables> </instance>
I get a segmentation error.
The parsing should give error because y isn't defined, but I was expecting an exception, not a segmentation error.
y
The problem is in "XMLParserTags.cc", in XMLParser::VarTagAction::beginTag(), where in a case of error an exception is created but not throw
XMLParser::VarTagAction::beginTag()
if(this->parser->variablesList[as] == NULL) runtime_error("Variable as " + as + "does not exist");
I strongly suggest to throw the error (and to add a space before "does"; maybe a double quote), something like
if(this->parser->variablesList[as] == NULL) throw runtime_error("Variable as \"" + as + "\" does not exist");
Otherwise in the following code
XVariable *similar = (XVariable *) this->parser->variablesList[as]; variable = new XVariable(id, similar->domain);
similar become nullptr (or NULL, if you prefer) and similar->domain cause a segmentation error.
similar
nullptr
NULL
similar->domain
Another similar problem is in XMLParser::MatrixTagAction::text() (ever "XMLParserTags.cc") where instead of
XMLParser::MatrixTagAction::text()
if(this->parser->variablesList[name] == NULL) runtime_error("Matrix variable " + name + "does not exist");
I strongly suggest
if(this->parser->variablesList[name] == NULL) throw runtime_error("Matrix variable \"" + name + "\" does not exist");
You are right. It is done Thanks.
Parsing the following xml file with
testlib
I get a segmentation error.
The parsing should give error because
y
isn't defined, but I was expecting an exception, not a segmentation error.The problem is in "XMLParserTags.cc", in
XMLParser::VarTagAction::beginTag()
, where in a case of error an exception is created but not throwI strongly suggest to throw the error (and to add a space before "does"; maybe a double quote), something like
Otherwise in the following code
similar
becomenullptr
(orNULL
, if you prefer) andsimilar->domain
cause a segmentation error.Another similar problem is in
XMLParser::MatrixTagAction::text()
(ever "XMLParserTags.cc") where instead ofI strongly suggest