Skip to content

Commit d7c1324

Browse files
authored
Merge pull request #477 from sbmlteam/remove-warnings
Remove warnings
2 parents a0ce444 + a1c5de1 commit d7c1324

8 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/sbml/Model.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6444,7 +6444,7 @@ Model::createConstraintUnitsData(UnitFormulaFormatter * unitFormatter)
64446444
for (unsigned int n = 0; n < getNumConstraints(); n++)
64456445
{
64466446
Constraint* c = getConstraint(n);
6447-
sprintf(newId, "constraint_%u", n);
6447+
snprintf(newId, 15, "constraint_%u", n);
64486448
newID.assign(newId);
64496449
c->setInternalId(newID);
64506450

@@ -6470,7 +6470,7 @@ Model::createRuleUnitsData(UnitFormulaFormatter * unitFormatter)
64706470
// need to create an id for an algebbraic rule
64716471
if (r->getTypeCode() == SBML_ALGEBRAIC_RULE)
64726472
{
6473-
sprintf(newId, "alg_rule_%u", countAlg);
6473+
snprintf(newId, 12, "alg_rule_%u", countAlg);
64746474
newID.assign(newId);
64756475
r->setInternalId(newID);
64766476
static_cast <AlgebraicRule *> (r)->setInternalIdOnly();
@@ -6647,7 +6647,7 @@ Model::createEventUnitsData(UnitFormulaFormatter * unitFormatter)
66476647
{
66486648
Event* e = getEvent(n);
66496649

6650-
sprintf(newId, "event_%u", countEvents);
6650+
snprintf(newId, 12, "event_%u", countEvents);
66516651
newID.assign(newId);
66526652
e->setInternalId(newID);
66536653
countEvents++;

src/sbml/conversion/SBMLInferUnitsConverter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ SBMLInferUnitsConverter::convert()
221221
if (newId.empty())
222222
{
223223
/* create an id for the unitDef */
224-
sprintf(number, "%u", newIdCount);
224+
snprintf(number, 4, "%u", newIdCount);
225225
newId = "unitSid_" + string(number);
226226
newIdCount++;
227227

228228
/* double check that this id has not been used */
229229
while (mModel->getUnitDefinition(newId) != NULL)
230230
{
231-
sprintf(number, "%u", newIdCount);
231+
snprintf(number, 4, "%u", newIdCount);
232232
newId = "unitSid_" + string(number);
233233
newIdCount++;
234234
}

src/sbml/conversion/SBMLRateRuleConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ SBMLRateRuleConverter::createReactions()
13341334
r->setReversible(false);
13351335
r->setFast(false);
13361336
int id = mDocument->getModel()->getNumReactions();
1337-
sprintf(number, "%u", id);
1337+
snprintf(number, 4, "%u", id);
13381338
const std::string reactionId = "J" + string(number);
13391339
r->setId(reactionId);
13401340
bool itemAdded = false;

src/sbml/conversion/SBMLUnitsConverter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,14 +900,14 @@ SBMLUnitsConverter::applyNewUnitDefinition(SBase &sb, Model &m,
900900
}
901901
if (newId.empty())
902902
{
903-
sprintf(number, "%u", newIdCount);
903+
snprintf(number, 4, "%u", newIdCount);
904904
newId = "unitSid_" + string(number);
905905
newIdCount++;
906906

907907
/* double check that this id has not been used */
908908
while (m.getUnitDefinition(newId) != NULL)
909909
{
910-
sprintf(number, "%u", newIdCount);
910+
snprintf(number, 4, "%u", newIdCount);
911911
newId = "unitSid_" + string(number);
912912
newIdCount++;
913913
}

src/sbml/math/ASTNode.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ ASTNode::fillListOfNodes (ASTNodePredicate predicate, List* lst) const
11761176

11771177
void ASTNode::fillListOfNodesWithLevel(ASTNodePredicate predicate, ASTNodeLevels& vector_pairs, unsigned int level) const
11781178
{
1179-
if (this == NULL ||
1179+
if (this==NULL ||
11801180
(vector_pairs.size() == 1 && vector_pairs.back().second == NULL) ||
11811181
predicate == NULL)
11821182
return;
@@ -3803,6 +3803,8 @@ ASTNode::combineNumbers(std::vector<unsigned int>& numbers)
38033803
case AST_FUNCTION_POWER:
38043804
number = pow(number, getChild(*it)->getValue());
38053805
break;
3806+
default:
3807+
break;
38063808
}
38073809

38083810
}
@@ -3818,6 +3820,8 @@ ASTNode::combineNumbers(std::vector<unsigned int>& numbers)
38183820
case AST_PLUS:
38193821
number = number + (getChild(*it)->getValue());
38203822
break;
3823+
default:
3824+
break;
38213825
}
38223826
}
38233827
}

src/sbml/packages/distrib/util/DistribToAnnotationConverter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ DistribToAnnotationConverter::addFunctionDefinitionWith(Model* model, const stri
402402
args = "scale";
403403
ret = "scale*sqrt(pi/2)";
404404
break;
405+
default:
406+
//This function should never be called with any other types.
407+
break;
405408
}
406409

407410
if (!getWriteMeans()) {

src/sbml/packages/render/sbml/Style.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ Style::getGroup()
561561
bool
562562
Style::isSetGroup() const
563563
{
564-
return (&mGroup != NULL);
564+
return true; // (&mGroup != NULL) is always true.
565565
}
566566

567567

@@ -1176,7 +1176,7 @@ Style::getElementBySId(const std::string& id)
11761176

11771177
SBase* obj = NULL;
11781178

1179-
if (&mGroup != NULL)
1179+
if (isSetGroup())
11801180
{
11811181
if (mGroup.getId() == id)
11821182
{
@@ -1208,7 +1208,7 @@ Style::getElementByMetaId(const std::string& metaid)
12081208

12091209
SBase* obj = NULL;
12101210

1211-
if (&mGroup != NULL)
1211+
if (isSetGroup())
12121212
{
12131213
if (mGroup.getMetaId() == metaid)
12141214
{

src/sbml/xml/XMLOutputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ XMLOutputStream::writeComment (const std::string& programName,
998998
now->tm_year+1900, now->tm_mon+1, now->tm_mday,
999999
now->tm_hour, now->tm_min);
10001000
#else
1001-
sprintf(formattedDateAndTime, "%d-%02d-%02d %02d:%02d",
1001+
snprintf(formattedDateAndTime, 17, "%d-%02d-%02d %02d:%02d",
10021002
now->tm_year+1900, now->tm_mon+1, now->tm_mday,
10031003
now->tm_hour, now->tm_min);
10041004
#endif

0 commit comments

Comments
 (0)