Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RateRuleConverter crashes on unsupported math #394

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/sbml/conversion/SBMLRateRuleConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ SBMLRateRuleConverter::isPositive(const ASTNode* node, bool& posDeriv)
{
bool signDetermined = false;

if (!node)
return signDetermined;

// node will be refactored so should be able to detect sign from first child
ASTNodeType_t type = node->getType();

Expand Down
51 changes: 51 additions & 0 deletions src/sbml/conversion/test/TestSBMLRateRuleConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,56 @@ START_TEST(test_conversion_raterule_converter)
}
END_TEST


START_TEST(test_crash_converter)
{
ConversionProperties props;
props.addOption("inferReactions", true);

SBMLConverter* converter = new SBMLRateRuleConverter();
converter->setProperties(&props);

SBMLDocument* doc = new SBMLDocument(3, 2);
Model* model = doc->createModel();
model->setId("m");

Parameter* parameter1 = model->createParameter();
parameter1->setId("s");
parameter1->setConstant(false);
parameter1->setValue(0);

Parameter* parameter = model->createParameter();
parameter->setId("p");
parameter->setConstant(false);
parameter->setValue(0);

parameter = model->createParameter();
parameter->setId("k");
parameter->setConstant(true);
parameter->setValue(0);

RateRule* rr1 = model->createRateRule();
rr1->setVariable("s");
ASTNode *math = SBML_parseL3Formula("cos(s)");
rr1->setMath(math);
delete math;

RateRule* rr2 = model->createRateRule();
rr1->setVariable("s");
math = SBML_parseL3Formula("sin(s)");
rr1->setMath(math);
delete math;

converter->setDocument(doc);
fail_unless(converter->convert() == LIBSBML_OPERATION_FAILED);

delete converter;
delete doc;
}
END_TEST



START_TEST(test_conversion_raterule_converter_non_standard_stoichiometry)
{
// example 3.13 in Fages et al, TCS, 2015
Expand Down Expand Up @@ -681,6 +731,7 @@ create_suite_TestSBMLRateRuleConverter (void)
tcase_add_test(tcase, test_conversion_raterule_converter);
tcase_add_test(tcase, test_conversion_raterule_converter_non_standard_stoichiometry);
tcase_add_test(tcase, test_conversion_raterule_converter_hidden_variable);
tcase_add_test(tcase, test_crash_converter);
tcase_add_test(tcase, test_model);
tcase_add_test(tcase, test_model1);
tcase_add_test(tcase, test_model2);
Expand Down
Loading