From 4a176e897cd4255b6c08357a676c5b29664604e2 Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Tue, 10 Mar 2026 13:52:23 -0700 Subject: [PATCH 1/3] Remove warnings * sprintf->snprintf * Addresses of actual objects are never NULL * 'this' is never NULL * Add default cases for ASTNode switch statements. --- examples/c++/CMakeLists.txt | 8 ++++++++ src/sbml/Model.cpp | 6 +++--- src/sbml/conversion/SBMLInferUnitsConverter.cpp | 4 ++-- src/sbml/conversion/SBMLRateRuleConverter.cpp | 2 +- src/sbml/conversion/SBMLUnitsConverter.cpp | 4 ++-- src/sbml/math/ASTNode.cpp | 7 +++++-- .../distrib/util/DistribToAnnotationConverter.cpp | 3 +++ src/sbml/packages/render/sbml/Style.cpp | 6 +++--- src/sbml/xml/XMLOutputStream.cpp | 2 +- 9 files changed, 28 insertions(+), 14 deletions(-) diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 596e8e66dd..d65fdd11ca 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -48,6 +48,7 @@ foreach(example addModelHistory appendAnnotation callExternalValidator + checkNotesMarkdown convertSBML convertToL1V1 createExampleSBML @@ -91,6 +92,13 @@ if (WITH_LIBXML) target_link_libraries(example_cpp_rngvalidator LIBXML::LIBXML ${EXTRA_LIBS}) endif() +add_subdirectory(analyzeTags) +add_subdirectory(checkTestCases) +add_subdirectory(compileTagsFor) +add_subdirectory(createSyntacticTests) +add_subdirectory(generateTestsFrom) + + # run examples as test add_test(NAME test_cxx_addCVTerms diff --git a/src/sbml/Model.cpp b/src/sbml/Model.cpp index 61320577a5..757e4dcf9b 100644 --- a/src/sbml/Model.cpp +++ b/src/sbml/Model.cpp @@ -6444,7 +6444,7 @@ Model::createConstraintUnitsData(UnitFormulaFormatter * unitFormatter) for (unsigned int n = 0; n < getNumConstraints(); n++) { Constraint* c = getConstraint(n); - sprintf(newId, "constraint_%u", n); + snprintf(newId, 15, "constraint_%u", n); newID.assign(newId); c->setInternalId(newID); @@ -6470,7 +6470,7 @@ Model::createRuleUnitsData(UnitFormulaFormatter * unitFormatter) // need to create an id for an algebbraic rule if (r->getTypeCode() == SBML_ALGEBRAIC_RULE) { - sprintf(newId, "alg_rule_%u", countAlg); + snprintf(newId, 12, "alg_rule_%u", countAlg); newID.assign(newId); r->setInternalId(newID); static_cast (r)->setInternalIdOnly(); @@ -6647,7 +6647,7 @@ Model::createEventUnitsData(UnitFormulaFormatter * unitFormatter) { Event* e = getEvent(n); - sprintf(newId, "event_%u", countEvents); + snprintf(newId, 12, "event_%u", countEvents); newID.assign(newId); e->setInternalId(newID); countEvents++; diff --git a/src/sbml/conversion/SBMLInferUnitsConverter.cpp b/src/sbml/conversion/SBMLInferUnitsConverter.cpp index ebf4107240..30cbcad3fc 100644 --- a/src/sbml/conversion/SBMLInferUnitsConverter.cpp +++ b/src/sbml/conversion/SBMLInferUnitsConverter.cpp @@ -221,14 +221,14 @@ SBMLInferUnitsConverter::convert() if (newId.empty()) { /* create an id for the unitDef */ - sprintf(number, "%u", newIdCount); + snprintf(number, 4, "%u", newIdCount); newId = "unitSid_" + string(number); newIdCount++; /* double check that this id has not been used */ while (mModel->getUnitDefinition(newId) != NULL) { - sprintf(number, "%u", newIdCount); + snprintf(number, 4, "%u", newIdCount); newId = "unitSid_" + string(number); newIdCount++; } diff --git a/src/sbml/conversion/SBMLRateRuleConverter.cpp b/src/sbml/conversion/SBMLRateRuleConverter.cpp index e7812b185e..4e5cb03abb 100644 --- a/src/sbml/conversion/SBMLRateRuleConverter.cpp +++ b/src/sbml/conversion/SBMLRateRuleConverter.cpp @@ -1334,7 +1334,7 @@ SBMLRateRuleConverter::createReactions() r->setReversible(false); r->setFast(false); int id = mDocument->getModel()->getNumReactions(); - sprintf(number, "%u", id); + snprintf(number, 4, "%u", id); const std::string reactionId = "J" + string(number); r->setId(reactionId); bool itemAdded = false; diff --git a/src/sbml/conversion/SBMLUnitsConverter.cpp b/src/sbml/conversion/SBMLUnitsConverter.cpp index b08ca69ad3..b9e6487c1a 100644 --- a/src/sbml/conversion/SBMLUnitsConverter.cpp +++ b/src/sbml/conversion/SBMLUnitsConverter.cpp @@ -900,14 +900,14 @@ SBMLUnitsConverter::applyNewUnitDefinition(SBase &sb, Model &m, } if (newId.empty()) { - sprintf(number, "%u", newIdCount); + snprintf(number, 4, "%u", newIdCount); newId = "unitSid_" + string(number); newIdCount++; /* double check that this id has not been used */ while (m.getUnitDefinition(newId) != NULL) { - sprintf(number, "%u", newIdCount); + snprintf(number, 4, "%u", newIdCount); newId = "unitSid_" + string(number); newIdCount++; } diff --git a/src/sbml/math/ASTNode.cpp b/src/sbml/math/ASTNode.cpp index 6457858ef6..46d9a8c9e5 100644 --- a/src/sbml/math/ASTNode.cpp +++ b/src/sbml/math/ASTNode.cpp @@ -1176,8 +1176,7 @@ ASTNode::fillListOfNodes (ASTNodePredicate predicate, List* lst) const void ASTNode::fillListOfNodesWithLevel(ASTNodePredicate predicate, ASTNodeLevels& vector_pairs, unsigned int level) const { - if (this == NULL || - (vector_pairs.size() == 1 && vector_pairs.back().second == NULL) || + if ((vector_pairs.size() == 1 && vector_pairs.back().second == NULL) || predicate == NULL) return; @@ -3803,6 +3802,8 @@ ASTNode::combineNumbers(std::vector& numbers) case AST_FUNCTION_POWER: number = pow(number, getChild(*it)->getValue()); break; + default: + break; } } @@ -3818,6 +3819,8 @@ ASTNode::combineNumbers(std::vector& numbers) case AST_PLUS: number = number + (getChild(*it)->getValue()); break; + default: + break; } } } diff --git a/src/sbml/packages/distrib/util/DistribToAnnotationConverter.cpp b/src/sbml/packages/distrib/util/DistribToAnnotationConverter.cpp index 3a7d1bdc6b..ef295cfab5 100644 --- a/src/sbml/packages/distrib/util/DistribToAnnotationConverter.cpp +++ b/src/sbml/packages/distrib/util/DistribToAnnotationConverter.cpp @@ -402,6 +402,9 @@ DistribToAnnotationConverter::addFunctionDefinitionWith(Model* model, const stri args = "scale"; ret = "scale*sqrt(pi/2)"; break; + default: + //This function should never be called with any other types. + break; } if (!getWriteMeans()) { diff --git a/src/sbml/packages/render/sbml/Style.cpp b/src/sbml/packages/render/sbml/Style.cpp index 84db2c7344..ee3269db24 100644 --- a/src/sbml/packages/render/sbml/Style.cpp +++ b/src/sbml/packages/render/sbml/Style.cpp @@ -561,7 +561,7 @@ Style::getGroup() bool Style::isSetGroup() const { - return (&mGroup != NULL); + return true; // (&mGroup != NULL) is always true. } @@ -1176,7 +1176,7 @@ Style::getElementBySId(const std::string& id) SBase* obj = NULL; - if (&mGroup != NULL) + if (isSetGroup()) { if (mGroup.getId() == id) { @@ -1208,7 +1208,7 @@ Style::getElementByMetaId(const std::string& metaid) SBase* obj = NULL; - if (&mGroup != NULL) + if (isSetGroup()) { if (mGroup.getMetaId() == metaid) { diff --git a/src/sbml/xml/XMLOutputStream.cpp b/src/sbml/xml/XMLOutputStream.cpp index 5bfc44cb6c..c361fba674 100644 --- a/src/sbml/xml/XMLOutputStream.cpp +++ b/src/sbml/xml/XMLOutputStream.cpp @@ -998,7 +998,7 @@ XMLOutputStream::writeComment (const std::string& programName, now->tm_year+1900, now->tm_mon+1, now->tm_mday, now->tm_hour, now->tm_min); #else - sprintf(formattedDateAndTime, "%d-%02d-%02d %02d:%02d", + snprintf(formattedDateAndTime, 17, "%d-%02d-%02d %02d:%02d", now->tm_year+1900, now->tm_mon+1, now->tm_mday, now->tm_hour, now->tm_min); #endif From 8c1e40e446da2b6370065cc6c175918a97b3830f Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Tue, 10 Mar 2026 14:03:48 -0700 Subject: [PATCH 2/3] Revert inadvertent commit. --- examples/c++/CMakeLists.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index d65fdd11ca..596e8e66dd 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -48,7 +48,6 @@ foreach(example addModelHistory appendAnnotation callExternalValidator - checkNotesMarkdown convertSBML convertToL1V1 createExampleSBML @@ -92,13 +91,6 @@ if (WITH_LIBXML) target_link_libraries(example_cpp_rngvalidator LIBXML::LIBXML ${EXTRA_LIBS}) endif() -add_subdirectory(analyzeTags) -add_subdirectory(checkTestCases) -add_subdirectory(compileTagsFor) -add_subdirectory(createSyntacticTests) -add_subdirectory(generateTestsFrom) - - # run examples as test add_test(NAME test_cxx_addCVTerms From a1c5de165389ce866752a64ed7790991edf6f4b2 Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Tue, 10 Mar 2026 14:27:19 -0700 Subject: [PATCH 3/3] Revert: we explicitly test this. I'm not sure testing calling a function on NULL is a good idea? But it's there, I guess. --- src/sbml/math/ASTNode.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sbml/math/ASTNode.cpp b/src/sbml/math/ASTNode.cpp index 46d9a8c9e5..51667fa515 100644 --- a/src/sbml/math/ASTNode.cpp +++ b/src/sbml/math/ASTNode.cpp @@ -1176,7 +1176,8 @@ ASTNode::fillListOfNodes (ASTNodePredicate predicate, List* lst) const void ASTNode::fillListOfNodesWithLevel(ASTNodePredicate predicate, ASTNodeLevels& vector_pairs, unsigned int level) const { - if ((vector_pairs.size() == 1 && vector_pairs.back().second == NULL) || + if (this==NULL || + (vector_pairs.size() == 1 && vector_pairs.back().second == NULL) || predicate == NULL) return;