spfactor.c, cktnames.c, don't crash when simulating "nothing"

reported by Siddhant Saraf in
> [ngspice:discussion] "out of memory" error : simulating a 2bit AND gate"

This comes in two flavours,
   1) an empty circuit
   2) a xspice circuit with exclusively xspice event nodes
This commit is contained in:
rlar 2015-02-08 21:57:07 +01:00
parent 8d44da4741
commit 8e65614d31
5 changed files with 57 additions and 2 deletions

View File

@ -340,6 +340,11 @@ spFactor(MatrixPtr Matrix)
Size = Matrix->Size;
if (Size == 0) {
Matrix->Factored = YES;
return (Matrix->Error = spOKAY);
}
if (Matrix->Diag[1]->Real == 0.0) return ZeroPivot( Matrix, 1 );
Matrix->Diag[1]->Real = 1.0 / Matrix->Diag[1]->Real;
@ -443,6 +448,12 @@ FactorComplexMatrix( MatrixPtr Matrix )
assert(Matrix->Complex);
Size = Matrix->Size;
if (Size == 0) {
Matrix->Factored = YES;
return (Matrix->Error = spOKAY);
}
pElement = Matrix->Diag[1];
if (ELEMENT_MAG(pElement) == 0.0) return ZeroPivot( Matrix, 1 );
/* Cmplx expr: *pPivot = 1.0 / *pPivot. */

View File

@ -22,7 +22,7 @@ CKTnames(CKTcircuit *ckt, int *numNames, IFuid **nameList)
int i;
*numNames = ckt->CKTmaxEqNum-1;
*nameList = TMALLOC(IFuid, *numNames);
if ((*nameList) == NULL) return(E_NOMEM);
if (*numNames && (*nameList) == NULL) return(E_NOMEM);
i=0;
for (here = ckt->CKTnodes->next; here; here = here->next) {
(*nameList) [i++] = here->name;

View File

@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in
TESTS = bugs-1.cir dollar-1.cir
TESTS = bugs-1.cir dollar-1.cir empty-1.cir
TESTS_ENVIRONMENT = ngspice_vpath=$(srcdir) $(SHELL) $(top_srcdir)/tests/bin/check.sh $(top_builddir)/src/ngspice

View File

@ -0,0 +1,18 @@
check that we can survive emptiness
* (exec-spice "ngspice -b %s")
* Nothingness, No circuit elements at all.
* We have only the implicit node "0"
* Checks whether we can live with a
* zero times zero circuit matrix
.control
op
tran 0.1m 1m
ac lin 3 1kHz 2kHz
echo "TEST: done"
quit 0
.endc
.end

View File

@ -0,0 +1,26 @@
Circuit: check that we can survive emptiness
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 1
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Initial Transient Solution
--------------------------
Node Voltage
---- -------
No. of Data Rows : 59
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 3
TEST: done