replaced MAXMSG with MAXID
added a check if demandName is too long
This commit is contained in:
mariosmsk
2019-03-26 17:19:08 +02:00
parent 8c5e383692
commit 08799eb276
2 changed files with 7 additions and 4 deletions

View File

@@ -1234,7 +1234,7 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value)
if (demand->Pat == tmpPat) if (demand->Pat == tmpPat)
{ {
demand->Pat = pat; demand->Pat = pat;
demand->Name = xstrcpy(&demand->Name, "", MAXMSG); demand->Name = xstrcpy(&demand->Name, "", MAXID);
} }
} }
} }
@@ -2776,11 +2776,14 @@ int DLLEXPORT EN_setdemandname(EN_Project p, int nodeIndex, int demandIndex,
if (!p->Openflag) return 102; if (!p->Openflag) return 102;
if (nodeIndex <= 0 || nodeIndex > p->network.Njuncs) return 203; if (nodeIndex <= 0 || nodeIndex > p->network.Njuncs) return 203;
// Check that demandName is not too long
if (strlen(demandName) > MAXID) return 250;
// Locate demand category record and assign demandName to it // Locate demand category record and assign demandName to it
for (d = p->network.Node[nodeIndex].D; for (d = p->network.Node[nodeIndex].D;
n < demandIndex && d->next != NULL; d = d->next) n++; n < demandIndex && d->next != NULL; d = d->next) n++;
if (n != demandIndex) return 253; if (n != demandIndex) return 253;
d->Name = xstrcpy(&d->Name, demandName, MAXMSG); d->Name = xstrcpy(&d->Name, demandName, MAXID);
return 0; return 0;
} }

View File

@@ -742,7 +742,7 @@ int demanddata(Project *pr)
// with what is specified in this section // with what is specified in this section
demand->Base = y; demand->Base = y;
demand->Pat = p; demand->Pat = p;
demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXMSG); demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXID);
hyd->NodeDemand[j] = MISSING; // marker - next iteration will append a new category. hyd->NodeDemand[j] = MISSING; // marker - next iteration will append a new category.
} }
@@ -755,7 +755,7 @@ int demanddata(Project *pr)
if (demand == NULL) return 101; if (demand == NULL) return 101;
demand->Base = y; demand->Base = y;
demand->Pat = p; demand->Pat = p;
demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXMSG); demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXID);
demand->next = NULL; demand->next = NULL;
cur_demand->next = demand; cur_demand->next = demand;
} }