xcsp3team / XCSP3-CPP-Parser

XCSP3 Core Parser in C++
MIT License
19 stars 11 forks source link

no throw for a couple of error #9

Closed massimomorara closed 7 years ago

massimomorara commented 7 years ago

Parsing the following xml file with 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.

The problem is in "XMLParserTags.cc", in XMLParser::VarTagAction::beginTag(), where in a case of error an exception is created but not throw

     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.

Another similar problem is in XMLParser::MatrixTagAction::text() (ever "XMLParserTags.cc") where instead of

     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");
xcsp3team commented 7 years ago

You are right. It is done Thanks.