From e4cc63417bffd592a093253e2b96d660f937e51a Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 1 Dec 2012 10:37:42 +0100 Subject: [PATCH] ltraacct.c, bug fix reported by Gary Hennigan on tracker http://sourceforge.net/tracker/index.php?func=detail&aid=3591132&group_id=38962&atid=423915 access to uninitialized memory, trying to acquire the "time" of a projected auxiliary timestep in the past. now using the following auxiliary timestep t[-1] voltage(t[-1]) === voltage(t[0]) and t[-1] === t[0] - (t[1] - t[0]) the details are not understood, but thats certainly better than accessing uninitialized memory. --- src/spicelib/devices/ltra/ltraacct.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/spicelib/devices/ltra/ltraacct.c b/src/spicelib/devices/ltra/ltraacct.c index 4b96dcb8f..c5c07a3b1 100644 --- a/src/spicelib/devices/ltra/ltraacct.c +++ b/src/spicelib/devices/ltra/ltraacct.c @@ -159,6 +159,8 @@ LTRAaccept(CKTcircuit *ckt, GENmodel *inModel) return (error); } #else + double dt_01, dt_12; + /* * remove the hack here - store the total inputs for the last 2 or 3 * timesteps @@ -182,18 +184,19 @@ LTRAaccept(CKTcircuit *ckt, GENmodel *inModel) v6 = ckt->CKTtimeIndex < 2 ? v5 : (*(here->LTRAv2 + ckt->CKTtimeIndex - 2) + *(here->LTRAi2 + ckt->CKTtimeIndex - 2) * model->LTRAimped) * model->LTRAattenuation; - d1 = (v1 - v2) / (*(ckt->CKTtimePoints + - ckt->CKTtimeIndex) - *(ckt->CKTtimePoints + - ckt->CKTtimeIndex - 1)); - d2 = (v2 - v3) / (*(ckt->CKTtimePoints + - ckt->CKTtimeIndex - 1) - *(ckt->CKTtimePoints + - ckt->CKTtimeIndex - 2)); - d3 = (v4 - v5) / (*(ckt->CKTtimePoints + - ckt->CKTtimeIndex) - *(ckt->CKTtimePoints + - ckt->CKTtimeIndex - 1)); - d4 = (v5 - v6) / (*(ckt->CKTtimePoints + - ckt->CKTtimeIndex - 1) - *(ckt->CKTtimePoints + - ckt->CKTtimeIndex - 2)); + + dt_01 = (*(ckt->CKTtimePoints + ckt->CKTtimeIndex) - + *(ckt->CKTtimePoints + ckt->CKTtimeIndex - 1)); + + dt_12 = (ckt->CKTtimeIndex < 2) + ? dt_01 + : (*(ckt->CKTtimePoints + ckt->CKTtimeIndex - 1) - + *(ckt->CKTtimePoints + ckt->CKTtimeIndex - 2)); + + d1 = (v1 - v2) / dt_01; + d2 = (v2 - v3) / dt_12; + d3 = (v4 - v5) / dt_01; + d4 = (v5 - v6) / dt_12; /* * here we have a big problem with the scheme boxed by the *s below.