From bf1dfa012757212afcab4207e652febea349613d Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 7 Jun 2023 16:25:24 +0200 Subject: [PATCH 01/16] Prevent crash if s == NULL --- src/frontend/numparam/xpressn.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index 7df535340..e7ce0e1ee 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -1395,6 +1395,8 @@ nupa_assignment(dico_t *dico, const char *s, char mode) bug: we cannot rely on the transformed line, must re-parse everything! */ { + if (!s || !*s) + return 1; /* s has the format: ident = expression; ident= expression ... */ const char * const s_end = s + strlen(s); const char *p = s; From 72496da4c9aa6838f441ed5d671203cec172ba1e Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 9 Jun 2023 14:44:40 +0200 Subject: [PATCH 02/16] Skip the title line when re-sorting parameters and removing .meas statement. --- src/frontend/inp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index ed9415156..5fe09d26b 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -979,7 +979,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) ft_curckt->ci_meas = NULL; } - for (dd = deck; dd; dd = dd->nextcard) { + for (dd = deck->nextcard; dd; dd = dd->nextcard) { /* skip title line */ /* all parameter lines should be sequentially ordered and placed at beginning of deck */ if (ciprefix(".para", dd->line)) { From cdf66fac6b74b90eed2ccaf186ddd51d0cedc71a Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 9 Jun 2023 14:45:43 +0200 Subject: [PATCH 03/16] Error message up to now was strictly for command line interactive use only. Improve error message when parsing .ac lines. --- src/spicelib/parser/inp2dot.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/spicelib/parser/inp2dot.c b/src/spicelib/parser/inp2dot.c index f1ba03623..bf035e52d 100644 --- a/src/spicelib/parser/inp2dot.c +++ b/src/spicelib/parser/inp2dot.c @@ -182,6 +182,7 @@ dot_ac(char *line, CKTcircuit *ckt, INPtables *tab, struct card *current, IFvalue *parm; /* a pointer to a value struct for function returns */ int which; /* which analysis we are performing */ char *steptype; /* ac analysis, type of stepping function */ + bool pdef = FALSE; /* issue a warning if default parameters are used */ NG_IGNORE(gnode); @@ -193,15 +194,33 @@ dot_ac(char *line, CKTcircuit *ckt, INPtables *tab, struct card *current, } IFC(newAnalysis, (ckt, which, "AC Analysis", &foo, task)); INPgetTok(&line, &steptype, 1); /* get DEC, OCT, or LIN */ + if (!*steptype || (!ciprefix("dec", steptype) && !ciprefix("oct", steptype) && !ciprefix("lin", steptype))) { + current->error = "Missing DEC, OCT, or LIN\n"; + return (0); + } ptemp.iValue = 1; GCA(INPapName, (ckt, which, foo, steptype, &ptemp)); tfree(steptype); + parm = INPgetValue(ckt, &line, IF_INTEGER, tab); /* number of points */ + if (parm->iValue == 0) + pdef = TRUE; GCA(INPapName, (ckt, which, foo, "numsteps", parm)); + + if(!isdigit(*line)) + pdef = TRUE; parm = INPgetValue(ckt, &line, IF_REAL, tab); /* fstart */ GCA(INPapName, (ckt, which, foo, "start", parm)); + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* fstop */ + if (parm->rValue == 0) + pdef = TRUE; GCA(INPapName, (ckt, which, foo, "stop", parm)); + + if (pdef) { + fprintf(stderr, "Warning, ngspice assumes default parameter(s) for ac simulation\n"); + fprintf(stderr, " Check your ac or .ac line\n\n"); + } return (0); } From d76e7362e700fb745a543861803b1a013668d284 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 9 Jun 2023 16:09:57 +0200 Subject: [PATCH 04/16] Make the error message a little more reasonable. Unfortunately the current setup does not easily allow naming the offending command. --- src/frontend/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/display.c b/src/frontend/display.c index a85a30726..a286289f5 100644 --- a/src/frontend/display.c +++ b/src/frontend/display.c @@ -129,7 +129,7 @@ DISPDEVICE device[] = { (disp_fn_Track_t *) NODEV, (disp_fn_MakeMenu_t *) NODEV, (disp_fn_MakeDialog_t *) NODEV, (disp_fn_Input_t *) NODEV, gen_DatatoScreen, }, - { "PrinterOnly", 0, 0, 24, 80, 0, 0, + { "BatchMode/PrinterOnly", 0, 0, 24, 80, 0, 0, (disp_fn_Init_t *) NODEV, (disp_fn_NewViewport_t *) NODEV, (disp_fn_Close_t *) NOP, (disp_fn_Clear_t *) NODEV, (disp_fn_DrawLine_t *) NODEV, (disp_fn_Arc_t *) NODEV, (disp_fn_Text_t *) NODEV, From 28f641b318132f550c1c6832ce12697ca8841e0e Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 9 Jun 2023 16:10:37 +0200 Subject: [PATCH 05/16] Remove the error message when a simulation has been started via the .control section. --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.c b/src/main.c index bba99a714..eecf01f04 100644 --- a/src/main.c +++ b/src/main.c @@ -1403,6 +1403,8 @@ int main(int argc, char **argv) if (ft_batchmode) { + int error3 = 1; + /* If we get back here in batch mode then something is wrong, * so exit. */ @@ -1425,6 +1427,9 @@ int main(int argc, char **argv) cp_interactive = FALSE; + /* Check if a simulation has run from a .control section */ + cp_getvar("sim_status", CP_NUM, &error3, 0); + if (rflag) { /* If -r is specified, then dot cards (.width, .plot, .print, .op, .meas, .tf) are ignored, except .save, which has been handled by ft_dotsaves() @@ -1443,6 +1448,10 @@ int main(int argc, char **argv) if (ft_cktcoms(FALSE) || error2) sp_shutdown(EXIT_BAD); } + else if (error3 == 0) { + fprintf(stdout, "Note: Simulation executed from .control section \n"); + sp_shutdown(EXIT_NORMAL); + } else { fprintf(stderr, "Note: No \".plot\", \".print\", or \".fourier\" lines; " From 630e800bd6227aac269e8201c7ccb596494059d8 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 9 Jun 2023 16:31:04 +0200 Subject: [PATCH 06/16] The 'plot' command is not available in batch mode. Issue a warning and ignore it. --- src/frontend/com_plot.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/frontend/com_plot.c b/src/frontend/com_plot.c index 6758dbd04..b151849bb 100644 --- a/src/frontend/com_plot.c +++ b/src/frontend/com_plot.c @@ -7,11 +7,17 @@ #include "com_plot.h" +extern bool ft_batchmode; /* plot name ... [xl[imit]] xlo xhi] [yl[imit ylo yhi] [vs xname] */ void com_plot(wordlist *wl) { + if (ft_batchmode) { + fprintf(stderr, "\nWarning: command 'plot' is not available during batch simulation, ignored!\n"); + fprintf(stderr, " You may use Gnuplot instead.\n\n"); + return; + } plotit(wl, NULL, NULL); } From bda4a83dc659729096887850ef79121522b24354 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Mon, 12 Jun 2023 23:20:46 +0200 Subject: [PATCH 07/16] Revert "Skip the title line when re-sorting parameters" This reverts commit 72496da4c9aa6838f441ed5d671203cec172ba1e. --- src/frontend/inp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 5fe09d26b..ed9415156 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -979,7 +979,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) ft_curckt->ci_meas = NULL; } - for (dd = deck->nextcard; dd; dd = dd->nextcard) { /* skip title line */ + for (dd = deck; dd; dd = dd->nextcard) { /* all parameter lines should be sequentially ordered and placed at beginning of deck */ if (ciprefix(".para", dd->line)) { From 2740d9a79b269742920f83a6e265bdcadc7116ed Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Tue, 13 Jun 2023 08:30:56 +0100 Subject: [PATCH 08/16] Fix Bug #635 - "Starting ngspice with HOME env variable unset causes segfault". --- src/main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index eecf01f04..7957cc7f2 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,7 @@ #ifdef HAVE_GNUREADLINE # include # include +# include "../misc/tilde.h" #endif /* editline development has added the following typdef to readline.h in 06/2018. @@ -614,11 +615,15 @@ static void app_rl_init(void) { #if defined(HAVE_GNUREADLINE) || defined(HAVE_BSDEDITLINE) + char *home; + /* --- set up readline params --- */ - strcpy(history_file, getenv("HOME")); - strcat(history_file, "/."); - strcat(history_file, application_name); - strcat(history_file, "_history"); + + if (get_local_home(0, &home) < 0) + return; + snprintf(history_file, sizeof history_file, "%s/.%s_history", + home, application_name); + tfree(home); using_history(); read_history(history_file); From b72f9516ac85793af01b343eb7779a9b4a7ba56f Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 13 Jun 2023 19:56:07 +0200 Subject: [PATCH 09/16] Prevent crash if *line == NULL --- src/spicelib/parser/inpgtok.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/spicelib/parser/inpgtok.c b/src/spicelib/parser/inpgtok.c index 58ece2fc1..189420fae 100644 --- a/src/spicelib/parser/inpgtok.c +++ b/src/spicelib/parser/inpgtok.c @@ -31,6 +31,9 @@ INPgetTok(char **line, char **token, int gobble) char *point; int signstate; + if (!*line) + return (E_PARMVAL); + /* scan along throwing away garbage characters until end of line or a separation char is found */ for (point = *line; *point != '\0'; point++) { From 216e5cb58b838fce2cbf3d5d4a99ab0591727fd9 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 13 Jun 2023 19:57:19 +0200 Subject: [PATCH 10/16] Skip title line when resorting .params, .meas, .temp --- src/frontend/inp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index ed9415156..264a95132 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -980,6 +980,11 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) } for (dd = deck; dd; dd = dd->nextcard) { + /* first line is title line */ + if (deck == dd) { + prev_card = dd; + continue; + } /* all parameter lines should be sequentially ordered and placed at beginning of deck */ if (ciprefix(".para", dd->line)) { From 818bd19798342a9716981fd8ff5ca8e822d6bb6e Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 13 Jun 2023 20:02:27 +0200 Subject: [PATCH 11/16] Revert "Prevent crash if *line == NULL" This reverts commit b72f9516ac85793af01b343eb7779a9b4a7ba56f. --- src/spicelib/parser/inpgtok.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/spicelib/parser/inpgtok.c b/src/spicelib/parser/inpgtok.c index 189420fae..58ece2fc1 100644 --- a/src/spicelib/parser/inpgtok.c +++ b/src/spicelib/parser/inpgtok.c @@ -31,9 +31,6 @@ INPgetTok(char **line, char **token, int gobble) char *point; int signstate; - if (!*line) - return (E_PARMVAL); - /* scan along throwing away garbage characters until end of line or a separation char is found */ for (point = *line; *point != '\0'; point++) { From a244e023c4a13613991a8faf454f9dac7db84397 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 13 Jun 2023 20:05:49 +0200 Subject: [PATCH 12/16] Prevent crash if *line == NULL --- src/spicelib/parser/inpgtok.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/spicelib/parser/inpgtok.c b/src/spicelib/parser/inpgtok.c index 58ece2fc1..be17a1a3f 100644 --- a/src/spicelib/parser/inpgtok.c +++ b/src/spicelib/parser/inpgtok.c @@ -31,6 +31,11 @@ INPgetTok(char **line, char **token, int gobble) char *point; int signstate; + if (!*line) { + *token = NULL; + return (E_PARMVAL); + } + /* scan along throwing away garbage characters until end of line or a separation char is found */ for (point = *line; *point != '\0'; point++) { From 5761b71ecddd24b657e344ab72e4615087c445b0 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 13 Jun 2023 20:06:27 +0200 Subject: [PATCH 13/16] improve comment --- src/frontend/inp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 264a95132..0b0c21f2c 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -980,7 +980,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) } for (dd = deck; dd; dd = dd->nextcard) { - /* first line is title line */ + /* first line is title line, skip it */ if (deck == dd) { prev_card = dd; continue; From 82796a6fa68be973cf31318f05be759548ac35e7 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 14 Jun 2023 15:34:45 +0200 Subject: [PATCH 14/16] Prevent crash if EXTERNAL voltage source is used Fixes 98763c0ad ("Note: ix: dc value used for op instead of transient time=0 value Former warning message or note only issued when dc value and value at transient time=0 differ.", 2022-09-20) --- src/spicelib/devices/vsrc/vsrctemp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/spicelib/devices/vsrc/vsrctemp.c b/src/spicelib/devices/vsrc/vsrctemp.c index 413a7392e..413e356e9 100644 --- a/src/spicelib/devices/vsrc/vsrctemp.c +++ b/src/spicelib/devices/vsrc/vsrctemp.c @@ -48,7 +48,9 @@ VSRCtemp(GENmodel *inModel, CKTcircuit *ckt) here->VSRCname); } else if (here->VSRCdcGiven && here->VSRCfuncTGiven - && here->VSRCfunctionType != TRNOISE && here->VSRCfunctionType != TRRANDOM) { + && here->VSRCfunctionType != TRNOISE + && here->VSRCfunctionType != TRRANDOM + && here->VSRCfunctionType != EXTERNAL) { /* DC value and transient time 0 values given */ double time0value; /* determine transient time 0 value */ From 8d9695d7d60d071a303fdedf7ff46ee64354848d Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 18 Jun 2023 10:29:43 +0200 Subject: [PATCH 15/16] Fix bug 637 Prevent crash when external current source is used. --- src/spicelib/devices/isrc/isrctemp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/spicelib/devices/isrc/isrctemp.c b/src/spicelib/devices/isrc/isrctemp.c index 207ed69a8..92f3e64a0 100644 --- a/src/spicelib/devices/isrc/isrctemp.c +++ b/src/spicelib/devices/isrc/isrctemp.c @@ -42,7 +42,9 @@ ISRCtemp(GENmodel *inModel, CKTcircuit *ckt) here->ISRCname); } else if (here->ISRCdcGiven && here->ISRCfuncTGiven - && here->ISRCfunctionType != TRNOISE && here->ISRCfunctionType != TRRANDOM) { + && here->ISRCfunctionType != TRNOISE + && here->ISRCfunctionType != TRRANDOM + && here->ISRCfunctionType != EXTERNAL) { /* DC value and transient time 0 values given */ double time0value; /* determine transient time 0 value */ From 3fd7bd21835f27edcd009a9bbc3c8fa33407bf0f Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 18 Jun 2023 10:32:01 +0200 Subject: [PATCH 16/16] Prevent crash when ControlledExit* is not initialized in ngspice shared library. --- src/sharedspice.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sharedspice.c b/src/sharedspice.c index af9dccd02..5e4145a55 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -2033,7 +2033,8 @@ ATTRIBUTE_NORETURN void shared_exit(int status) fl_exited = TRUE; bgtr(fl_exited, ng_ident, userptr); // set a flag that ngspice wants to be detached - ngexit(status, FALSE, coquit, ng_ident, userptr); + if(ngexit) + ngexit(status, FALSE, coquit, ng_ident, userptr); // finish and exit the worker thread #ifdef HAVE_LIBPTHREAD pthread_exit(NULL); @@ -2042,7 +2043,8 @@ ATTRIBUTE_NORETURN void shared_exit(int status) #endif } // set a flag in caller to detach ngspice.dll - ngexit(status, immediate, coquit, ng_ident, userptr); + if(ngexit) + ngexit(status, immediate, coquit, ng_ident, userptr); // jump back to finish the calling function if (!intermj)