From 5490c3c33ddc979017c47ddb738f1638a2af3e27 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 24 Apr 2026 15:28:49 +0200 Subject: [PATCH] ngspice crashes in eprvcd with 3 or more analog parameters. Fixed by changing the parameter sequence and zeroing the initial array. --- src/xspice/evt/evtprint.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/xspice/evt/evtprint.c b/src/xspice/evt/evtprint.c index 3e8b909f5..c5c8c04e2 100644 --- a/src/xspice/evt/evtprint.c +++ b/src/xspice/evt/evtprint.c @@ -594,7 +594,7 @@ EVTprintvcd(wordlist *wl) char *node_value[EPRINT_MAXARGS]; char *old_node_value[EPRINT_MAXARGS]; char node_ident[EPRINT_MAXARGS + 1]; - char vbuf[24][2][EPRINT_MAXARGS]; // Analog value strings + char vbuf[EPRINT_MAXARGS][2][24]; // Analog value strings CKTcircuit *ckt; @@ -607,6 +607,8 @@ EVTprintvcd(wordlist *wl) char *value; + memset(vbuf, 0, sizeof(vbuf)); + /* Check for the "-a" option (output analog values at timesteps) * and "-t nn": specifies the VCD timestep with range 1fs to 1s */ @@ -804,10 +806,10 @@ EVTprintvcd(wordlist *wl) if (ctx.node_vector[i]) { /* Analog node or expression. */ - sprintf(vbuf[0][i], "%.16g", get_real(i, 0.0, &ctx)); - node_value[i] = vbuf[0][i]; - old_node_value[i] = vbuf[1][i]; - strcpy(vbuf[1][i], vbuf[0][i]); + sprintf(vbuf[i][0], "%.16g", get_real(i, 0.0, &ctx)); + node_value[i] = vbuf[i][0]; + old_node_value[i] = vbuf[i][1]; + strcpy(vbuf[i][1], vbuf[i][0]); } else { /* This must return a pointer to a statically-allocated string. */