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..51667fa515 100644 --- a/src/sbml/math/ASTNode.cpp +++ b/src/sbml/math/ASTNode.cpp @@ -1176,7 +1176,7 @@ ASTNode::fillListOfNodes (ASTNodePredicate predicate, List* lst) const void ASTNode::fillListOfNodesWithLevel(ASTNodePredicate predicate, ASTNodeLevels& vector_pairs, unsigned int level) const { - if (this == NULL || + if (this==NULL || (vector_pairs.size() == 1 && vector_pairs.back().second == NULL) || predicate == NULL) return; @@ -3803,6 +3803,8 @@ ASTNode::combineNumbers(std::vector& numbers) case AST_FUNCTION_POWER: number = pow(number, getChild(*it)->getValue()); break; + default: + break; } } @@ -3818,6 +3820,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