From 5c59267768752479989c4382de3db6e87da9bc24 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 15 Aug 2010 17:16:51 +0000 Subject: [PATCH] check for shorted voltage sources, to avoid a segmentation fault --- ChangeLog | 7 +++++++ src/spicelib/devices/asrc/asrcset.c | 7 +++++++ src/spicelib/devices/ccvs/ccvsset.c | 6 ++++++ src/spicelib/devices/vcvs/vcvsset.c | 6 ++++++ src/spicelib/devices/vsrc/vsrcset.c | 6 ++++++ 5 files changed, 32 insertions(+) diff --git a/ChangeLog b/ChangeLog index a102c08b2..a5dc7b551 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-08-15 Robert Larice + * src/spicelib/devices/asrc/asrcset.c , + * src/spicelib/devices/ccvs/ccvsset.c , + * src/spicelib/devices/vcvs/vcvsset.c , + * src/spicelib/devices/vsrc/vsrcset.c : + check for shorted voltage sources, to avoid a segmentation fault + 2010-08-15 Robert Larice * src/maths/sparse/spdefs.h : fix txfree() prototype diff --git a/src/spicelib/devices/asrc/asrcset.c b/src/spicelib/devices/asrc/asrcset.c index 0444141f3..0ff1bda6e 100644 --- a/src/spicelib/devices/asrc/asrcset.c +++ b/src/spicelib/devices/asrc/asrcset.c @@ -64,6 +64,13 @@ if((here->ptr = SMPmakeElt(matrix, here->first, (second)->number))\ return E_PARMVAL; if( here->ASRCtype == ASRC_VOLTAGE) { + + if(here->ASRCposNode == here->ASRCnegNode) { + (*(SPfrontEnd->IFerror))(ERR_FATAL, + "instance %s is a shorted ASRC", &here->ASRCname); + return(E_UNSUPP); + } + here->ASRCposptr = (double **) REALLOC(here->ASRCposptr, (sizeof(double *)*(j+5))); TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCbranch); diff --git a/src/spicelib/devices/ccvs/ccvsset.c b/src/spicelib/devices/ccvs/ccvsset.c index 1a3831b08..b7aca6855 100644 --- a/src/spicelib/devices/ccvs/ccvsset.c +++ b/src/spicelib/devices/ccvs/ccvsset.c @@ -29,6 +29,12 @@ CCVSsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) for (here = model->CCVSinstances; here != NULL ; here=here->CCVSnextInstance) { + if(here->CCVSposNode == here->CCVSnegNode) { + (*(SPfrontEnd->IFerror))(ERR_FATAL, + "instance %s is a shorted CCVS", &here->CCVSname); + return(E_UNSUPP); + } + if(here->CCVSbranch==0) { error = CKTmkCur(ckt,&tmp,here->CCVSname, "branch"); if(error) return(error); diff --git a/src/spicelib/devices/vcvs/vcvsset.c b/src/spicelib/devices/vcvs/vcvsset.c index e643dc4fd..c7c97c548 100644 --- a/src/spicelib/devices/vcvs/vcvsset.c +++ b/src/spicelib/devices/vcvs/vcvsset.c @@ -30,6 +30,12 @@ VCVSsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) for (here = model->VCVSinstances; here != NULL ; here=here->VCVSnextInstance) { + if(here->VCVSposNode == here->VCVSnegNode) { + (*(SPfrontEnd->IFerror))(ERR_FATAL, + "instance %s is a shorted VCVS", &here->VCVSname); + return(E_UNSUPP); + } + if(here->VCVSbranch == 0) { error = CKTmkCur(ckt,&tmp,here->VCVSname,"branch"); if(error) return(error); diff --git a/src/spicelib/devices/vsrc/vsrcset.c b/src/spicelib/devices/vsrc/vsrcset.c index a7e0bf317..a4128d140 100644 --- a/src/spicelib/devices/vsrc/vsrcset.c +++ b/src/spicelib/devices/vsrc/vsrcset.c @@ -29,6 +29,12 @@ VSRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) for (here = model->VSRCinstances; here != NULL ; here=here->VSRCnextInstance) { + if(here->VSRCposNode == here->VSRCnegNode) { + (*(SPfrontEnd->IFerror))(ERR_FATAL, + "instance %s is a shorted VSRC", &here->VSRCname); + return(E_UNSUPP); + } + if(here->VSRCbranch == 0) { error = CKTmkCur(ckt,&tmp,here->VSRCname,"branch"); if(error) return(error);