Return error if node/link name is too long (#535)

* co-authored with @ehsan-shafiee

* removes errant slashes

* Throws correct error for ID name too long

* Revert "Throws correct error for ID name too long"

This reverts commit 57b4873f5882cb9fd983f7e1e5a703b9e442cd74.

* fixes #534 by bubbling error codes up from add node/link internal functions

* fixes tests on Mac at least

* fixes improper success code

* Error 252 (not 250) returned for ID name too long.

From errors.dat: DAT(252,"invalid ID name")
This commit is contained in:
Sam Hatchett
2019-10-09 10:47:45 -04:00
committed by GitHub
parent 5601973d67
commit 5f7fd55a36
4 changed files with 60 additions and 28 deletions

View File

@@ -173,12 +173,12 @@ int readdata(Project *pr)
net->Ncontrols = 0;
net->Nrules = 0;
// Patterns & Curves were created previously in netsize()
// Patterns & Curves were created previously in netsize()
parser->MaxPats = net->Npats;
parser->MaxCurves = net->Ncurves;
parser->PrevPat = NULL;
parser->PrevCurve = NULL;
// Initialize full line comment, input data section and error count
parser->LineComment[0] = '\0';
sect = -1;
@@ -472,10 +472,13 @@ int addnodeID(Network *net, int n, char *id)
**--------------------------------------------------------------
*/
{
if (findnode(net,id)) return 0;
if (findnode(net,id))
return 215; // duplicate id
if (strlen(id) > MAXID)
return 252; // invalid format (too long)
strncpy(net->Node[n].ID, id, MAXID);
hashtable_insert(net->NodeHashTable, net->Node[n].ID, n);
return 1;
return 0;
}
int addlinkID(Network *net, int n, char *id)
@@ -488,10 +491,13 @@ int addlinkID(Network *net, int n, char *id)
**--------------------------------------------------------------
*/
{
if (findlink(net,id)) return 0;
if (findlink(net,id))
return 215; // duplicate id
if (strlen(id) > MAXID)
return 252; // invalid formt (too long);
strncpy(net->Link[n].ID, id, MAXID);
hashtable_insert(net->LinkHashTable, net->Link[n].ID, n);
return 1;
return 0;
}
int addpattern(Network *network, char *id)
@@ -512,7 +518,7 @@ int addpattern(Network *network, char *id)
if (strcmp(id, network->Pattern[n].ID) == 0) return 0;
if (findpattern(network, id) > 0) return 0;
}
if (strlen(id) > MAXID) return 250;
if (strlen(id) > MAXID) return 252;
// Update pattern count & add a new pattern to the database
n = n + 2;
@@ -547,7 +553,7 @@ int addcurve(Network *network, char *id)
if (strcmp(id, network->Curve[n].ID) == 0) return 0;
if (findcurve(network, id) > 0) return 0;
}
if (strlen(id) > MAXID) return 250;
if (strlen(id) > MAXID) return 252;
n = n + 2;
network->Curve = (Scurve *)realloc(network->Curve, n * sizeof(Scurve));