Restrict the return vectors (malloced) to the voltage source type

given by the requested VSRC function type value (VSRC_PULSE etc.)
This commit is contained in:
Holger Vogt 2026-07-07 14:58:57 +02:00
parent 301051d1da
commit 3128841b99
1 changed files with 44 additions and 1 deletions

View File

@ -25,11 +25,42 @@ VSRCask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value, IFvalue *
{ {
VSRCinstance *here = (VSRCinstance*)inst; VSRCinstance *here = (VSRCinstance*)inst;
static char *msg = "Current and power not available in ac analysis"; static char *msg = "Current and power not available in ac analysis";
int temp; int temp, funtype = 0;
double *v, *w; double *v, *w;
NG_IGNORE(select); NG_IGNORE(select);
/* VSRC function types and instance parameter numbers are different. */
switch (which) {
case VSRC_PULSE:
funtype = PULSE;
break;
case VSRC_SINE:
funtype = SINE;
break;
case VSRC_EXP:
funtype = EXP;
break;
case VSRC_PWL:
funtype = PWL;
break;
case VSRC_SFFM:
funtype = SFFM;
break;
case VSRC_AM:
funtype = AM;
break;
case VSRC_TRNOISE:
funtype = TRNOISE;
break;
case VSRC_TRRANDOM:
funtype = TRRANDOM;
break;
case VSRC_SOUND:
funtype = SOUND;
break;
}
switch(which) { switch(which) {
case VSRC_DC: case VSRC_DC:
value->rValue = here->VSRCdcValue; value->rValue = here->VSRCdcValue;
@ -49,6 +80,18 @@ VSRCask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value, IFvalue *
case VSRC_TRNOISE: case VSRC_TRNOISE:
case VSRC_TRRANDOM: case VSRC_TRRANDOM:
case VSRC_SOUND: case VSRC_SOUND:
if (here->VSRCfunctionType != funtype) {
value->v.vec.rVec = TMALLOC(double, 1);
value->v.vec.rVec[0] = 0;
}
else {
temp = value->v.numValue = here->VSRCfunctionOrder;
v = value->v.vec.rVec = TMALLOC(double, here->VSRCfunctionOrder);
w = here->VSRCcoeffs;
while (temp--)
*v++ = *w++;
}
return (OK);
case VSRC_FCN_COEFFS: case VSRC_FCN_COEFFS:
temp = value->v.numValue = here->VSRCfunctionOrder; temp = value->v.numValue = here->VSRCfunctionOrder;
v = value->v.vec.rVec = TMALLOC(double, here->VSRCfunctionOrder); v = value->v.vec.rVec = TMALLOC(double, here->VSRCfunctionOrder);