Don't silently accept wrong user input (missing nodes, values).
Check for at leat 4 tokens (name, n1, n2, val/model/...). If the instance has not been set up correctly, bail out, prevent crash.
This commit is contained in:
parent
a3fef757a5
commit
e0ee0bf131
|
|
@ -32,7 +32,7 @@ void INP2C(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
int error1; /* secondary error code temporary */
|
||||
INPmodel *thismodel; /* pointer to model structure describing our model */
|
||||
GENmodel *mdfast = NULL; /* pointer to the actual model */
|
||||
GENinstance *fast; /* pointer to the actual instance */
|
||||
GENinstance *fast = NULL;/* pointer to the actual instance */
|
||||
IFvalue ptemp; /* a value structure to package resistance into */
|
||||
int waslead; /* flag to indicate that funny unlabeled number was found */
|
||||
double leadval; /* actual value of unlabeled number */
|
||||
|
|
@ -49,11 +49,25 @@ void INP2C(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
}
|
||||
}
|
||||
line = current->line;
|
||||
INPgetNetTok(&line, &name, 1);
|
||||
|
||||
INPgetNetTok(&line, &name, 1); /* Cname */
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid capacitor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
INPgetNetTok(&line, &nname1, 1); /* <node> */
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid capacitor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
INPgetNetTok(&line, &nname2, 1); /* <node> */
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid capacitor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
|
||||
INPinsert(&name, tab);
|
||||
INPgetNetTok(&line, &nname1, 1);
|
||||
INPtermInsert(ckt, &nname1, tab, &node1);
|
||||
INPgetNetTok(&line, &nname2, 1);
|
||||
INPtermInsert(ckt, &nname2, tab, &node2);
|
||||
|
||||
/* enable reading values like 4u7 */
|
||||
|
|
@ -109,7 +123,12 @@ void INP2C(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!fast || !fast->GENmodPtr) {
|
||||
fprintf(stderr, "\nWarning: Instance for capacitor '%s' could not be set up properly, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
|
||||
if (error1 == 0) { /* Looks like a number */
|
||||
ptemp.rValue = val;
|
||||
GCA(INPpName, ("capacitance", &ptemp, ckt, type, fast));
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ void INP2L(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
int error1; /* secondary error code temporary */
|
||||
INPmodel *thismodel; /* pointer to model structure describing our model */
|
||||
GENmodel *mdfast = NULL; /* pointer to the actual model */
|
||||
GENinstance *fast; /* pointer to the actual instance */
|
||||
GENinstance *fast = NULL;/* pointer to the actual instance */
|
||||
IFvalue ptemp; /* a value structure to package inductance into */
|
||||
int waslead; /* flag to indicate that funny unlabeled number was found */
|
||||
double leadval; /* actual value of unlabeled number */
|
||||
|
|
@ -49,14 +49,25 @@ void INP2L(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
}
|
||||
}
|
||||
line = current->line;
|
||||
INPgetNetTok(&line, &name, 1);
|
||||
INPinsert(&name, tab);
|
||||
INPgetNetTok(&line, &nname1, 1);
|
||||
INPtermInsert(ckt, &nname1, tab, &node1);
|
||||
INPgetNetTok(&line, &nname2, 1);
|
||||
INPtermInsert(ckt, &nname2, tab, &node2);
|
||||
INPgetNetTok(&line, &name, 1); /* Lname */
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid inductor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
INPgetNetTok(&line, &nname1, 1); /* <node> */
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid inductor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
INPgetNetTok(&line, &nname2, 1); /* <node> */
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid inductor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
|
||||
// val = INPevaluate(&line, &error1, 1);
|
||||
INPinsert(&name, tab);
|
||||
INPtermInsert(ckt, &nname1, tab, &node1);
|
||||
INPtermInsert(ckt, &nname2, tab, &node2);
|
||||
|
||||
/* enable reading values like 4u7 */
|
||||
if (newcompat.lt)
|
||||
|
|
@ -110,7 +121,12 @@ void INP2L(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!fast || !fast->GENmodPtr) {
|
||||
fprintf(stderr, "\nWarning: Instance for inductor '%s' could not be set up properly, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
|
||||
if (error1 == 0) { /* Looks like a number */
|
||||
ptemp.rValue = val;
|
||||
GCA(INPpName, ("inductance", &ptemp, ckt, type, fast));
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ void INP2R(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
int error1; /* secondary error code temporary */
|
||||
INPmodel *thismodel; /* pointer to model structure describing our model */
|
||||
GENmodel *mdfast = NULL; /* pointer to the actual model */
|
||||
GENinstance *fast; /* pointer to the actual instance */
|
||||
GENinstance *fast = NULL; /* pointer to the actual instance */
|
||||
IFvalue ptemp; /* a value structure to package resistance into */
|
||||
int waslead; /* flag to indicate that funny unlabeled number was found */
|
||||
double leadval; /* actual value of unlabeled number */
|
||||
|
|
@ -59,10 +59,23 @@ void INP2R(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
}
|
||||
line = current->line;
|
||||
INPgetNetTok(&line, &name, 1); /* Rname */
|
||||
INPinsert(&name, tab);
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid resistor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
INPgetNetTok(&line, &nname1, 1); /* <node> */
|
||||
INPtermInsert(ckt, &nname1, tab, &node1);
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid resistor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
INPgetNetTok(&line, &nname2, 1); /* <node> */
|
||||
if (*line == '\0') {
|
||||
fprintf(stderr, "\nWarning: '%s' is not a valid resistor instance line, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
|
||||
INPinsert(&name, tab);
|
||||
INPtermInsert(ckt, &nname1, tab, &node1);
|
||||
INPtermInsert(ckt, &nname2, tab, &node2);
|
||||
|
||||
/* enable reading values like 4k7 */
|
||||
|
|
@ -197,6 +210,11 @@ void INP2R(CKTcircuit *ckt, INPtables * tab, struct card *current)
|
|||
}
|
||||
}
|
||||
|
||||
if (!fast || !fast->GENmodPtr) {
|
||||
fprintf(stderr, "\nWarning: Instance for resistor '%s' could not be set up properly, ignored!\n\n", current->line);
|
||||
return;
|
||||
}
|
||||
|
||||
if (error1 == 0) { /* got a resistance above */
|
||||
ptemp.rValue = val;
|
||||
GCA(INPpName, ("resistance", &ptemp, ckt, type, fast));
|
||||
|
|
|
|||
Loading…
Reference in New Issue