From 09c876550fabda5006b7fc350247242c517950c7 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 21 Jul 2018 18:22:18 +0200 Subject: [PATCH] prevent string overflow by adding the string length to the cp_getvar parameters. Used only with CP_STRING --- src/frontend/com_ahelp.c | 2 +- src/frontend/com_display.c | 2 +- src/frontend/com_fft.c | 8 ++++---- src/frontend/com_hardcopy.c | 8 ++++---- src/frontend/device.c | 8 ++++---- src/frontend/diff.c | 6 +++--- src/frontend/fourier.c | 6 +++--- src/frontend/hpgl.c | 2 +- src/frontend/inp.c | 20 ++++++++++---------- src/frontend/inpcom.c | 12 ++++++------ src/frontend/measure.c | 4 ++-- src/frontend/misccoms.c | 2 +- src/frontend/numparam/spicenum.c | 2 +- src/frontend/nutinp.c | 2 +- src/frontend/outitf.c | 8 ++++---- src/frontend/plotting/agraf.c | 8 ++++---- src/frontend/plotting/gnuplot.c | 12 ++++++------ src/frontend/plotting/graf.c | 10 +++++----- src/frontend/plotting/plotcurv.c | 6 +++--- src/frontend/plotting/plotit.c | 4 ++-- src/frontend/plotting/xgraph.c | 4 ++-- src/frontend/postcoms.c | 14 +++++++------- src/frontend/postsc.c | 16 ++++++++-------- src/frontend/rawfile.c | 2 +- src/frontend/runcoms.c | 2 +- src/frontend/runcoms2.c | 2 +- src/frontend/spec.c | 8 ++++---- src/frontend/subckt.c | 12 ++++++------ src/frontend/terminal.c | 6 +++--- src/frontend/trannoise/1-f-code.c | 2 +- src/frontend/variable.c | 9 +++++++-- src/include/ngspice/cpextern.h | 2 +- src/main.c | 2 +- src/maths/cmaths/cmath4.c | 8 ++++---- src/maths/misc/randnumb.c | 2 +- src/sharedspice.c | 4 ++-- src/spicelib/analysis/cktdojob.c | 2 +- src/spicelib/analysis/cktsetup.c | 2 +- src/spicelib/analysis/noisean.c | 2 +- src/spicelib/devices/bsim3/b3par.c | 2 +- src/spicelib/devices/bsim3v0/b3v0par.c | 2 +- src/spicelib/devices/bsim3v1/b3v1par.c | 2 +- src/spicelib/devices/bsim3v32/b3v32par.c | 2 +- src/spicelib/devices/bsim4/b4par.c | 2 +- src/spicelib/devices/bsim4v5/b4v5par.c | 2 +- src/spicelib/devices/bsim4v6/b4v6par.c | 2 +- src/spicelib/devices/bsim4v7/b4v7par.c | 2 +- src/spicelib/devices/bsimsoi/b4soipar.c | 2 +- src/spicelib/devices/cap/capparam.c | 2 +- src/spicelib/devices/dio/dioparam.c | 2 +- src/spicelib/devices/hisim2/hsm2par.c | 2 +- src/spicelib/devices/hisimhv1/hsmhvpar.c | 2 +- src/spicelib/devices/hisimhv2/hsmhv2par.c | 2 +- src/spicelib/devices/mos1/mos1par.c | 2 +- src/spicelib/devices/mos2/mos2par.c | 2 +- src/spicelib/devices/mos3/mos3par.c | 2 +- src/spicelib/devices/res/resparam.c | 2 +- src/spicelib/devices/vdmos/vdmospar.c | 2 +- src/spicelib/parser/inpgmod.c | 2 +- 59 files changed, 139 insertions(+), 134 deletions(-) diff --git a/src/frontend/com_ahelp.c b/src/frontend/com_ahelp.c index f739c7071..c06b56993 100644 --- a/src/frontend/com_ahelp.c +++ b/src/frontend/com_ahelp.c @@ -38,7 +38,7 @@ com_ahelp(wordlist *wl) env |= E_NOPLOTS; /* determine level */ - if (cp_getvar("level", CP_STRING, slevel)) { + if (cp_getvar("level", CP_STRING, slevel, sizeof(slevel))) { switch (*slevel) { case 'b': level = 1; break; diff --git a/src/frontend/com_display.c b/src/frontend/com_display.c index b74df3b33..b6c9a7432 100644 --- a/src/frontend/com_display.c +++ b/src/frontend/com_display.c @@ -66,7 +66,7 @@ com_display(wordlist *wl) dvs = TMALLOC(struct dvec *, len); for (d = plot_cur->pl_dvecs, i = 0; d; d = d->v_next, i++) dvs[i] = d; - if (!cp_getvar("nosort", CP_BOOL, NULL)) + if (!cp_getvar("nosort", CP_BOOL, NULL, 0)) qsort(dvs, (size_t) len, sizeof(struct dvec *), dcomp); out_printf("Title: %s\n", plot_cur->pl_title); diff --git a/src/frontend/com_fft.c b/src/frontend/com_fft.c index 6159debd7..a1d86f7b0 100644 --- a/src/frontend/com_fft.c +++ b/src/frontend/com_fft.c @@ -76,9 +76,9 @@ com_fft(wordlist *wl) win = TMALLOC(double, length); maxt = time[length-1]; - if (!cp_getvar("specwindow", CP_STRING, window)) + if (!cp_getvar("specwindow", CP_STRING, window, sizeof(window))) strcpy(window, "hanning"); - if (!cp_getvar("specwindoworder", CP_NUM, &order)) + if (!cp_getvar("specwindoworder", CP_NUM, &order, 0)) order = 2; if (order < 2) order = 2; @@ -296,9 +296,9 @@ com_psd(wordlist *wl) win = TMALLOC(double, length); maxt = time[length-1]; - if (!cp_getvar("specwindow", CP_STRING, window)) + if (!cp_getvar("specwindow", CP_STRING, window, sizeof(window))) strcpy(window, "hanning"); - if (!cp_getvar("specwindoworder", CP_NUM, &order)) + if (!cp_getvar("specwindoworder", CP_NUM, &order, 0)) order = 2; if (order < 2) order = 2; diff --git a/src/frontend/com_hardcopy.c b/src/frontend/com_hardcopy.c index 075fcb3ec..bad18214a 100644 --- a/src/frontend/com_hardcopy.c +++ b/src/frontend/com_hardcopy.c @@ -35,7 +35,7 @@ com_hardcopy(wordlist *wl) int hc_button; int foundit; - if (!cp_getvar("hcopydev", CP_STRING, device)) + if (!cp_getvar("hcopydev", CP_STRING, device, sizeof(device))) *device = '\0'; if (wl) { @@ -48,7 +48,7 @@ com_hardcopy(wordlist *wl) tempf = TRUE; } - if (!cp_getvar("hcopydevtype", CP_STRING, buf)) + if (!cp_getvar("hcopydevtype", CP_STRING, buf, sizeof(buf))) devtype = "postscript"; else devtype = buf; @@ -161,7 +161,7 @@ com_hardcopy(wordlist *wl) if (*device) { #ifdef SYSTEM_PLOT5LPR if (!strcmp(devtype, "plot5") || !strcmp(devtype, "MFB")) { - if (!cp_getvar("lprplot5", CP_STRING, format)) + if (!cp_getvar("lprplot5", CP_STRING, format, size_of(format))) strcpy(format, SYSTEM_PLOT5LPR); (void) sprintf(buf, format, device, fname); fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); @@ -172,7 +172,7 @@ com_hardcopy(wordlist *wl) #ifdef SYSTEM_PSLPR if (!printed && !strcmp(devtype, "postscript")) { /* note: check if that was a postscript printer XXX */ - if (!cp_getvar("lprps", CP_STRING, format)) + if (!cp_getvar("lprps", CP_STRING, format, size_of(format))) strcpy(format, SYSTEM_PSLPR); (void) sprintf(buf, format, device, fname); fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); diff --git a/src/frontend/device.c b/src/frontend/device.c index 1fa48841e..0dbc57f33 100644 --- a/src/frontend/device.c +++ b/src/frontend/device.c @@ -235,7 +235,7 @@ static int count; void com_showmod(wordlist *wl) { - if (cp_getvar("altshow", CP_BOOL, NULL)) + if (cp_getvar("altshow", CP_BOOL, NULL, 0)) all_show(wl, 1); else all_show_old(wl, 1); @@ -245,7 +245,7 @@ com_showmod(wordlist *wl) void com_show(wordlist *wl) { - if (cp_getvar("altshow", CP_BOOL, NULL)) + if (cp_getvar("altshow", CP_BOOL, NULL, 0)) all_show(wl, 0); else all_show_old(wl, 0); @@ -273,7 +273,7 @@ all_show(wordlist *wl, int mode) return; } - if (!cp_getvar("width", CP_NUM, &screen_width)) + if (!cp_getvar("width", CP_NUM, &screen_width, 0)) screen_width = DEF_WIDTH; count = (screen_width - LEFT_WIDTH) / (DEV_WIDTH + 1); count = 1; @@ -435,7 +435,7 @@ all_show_old(wordlist *wl, int mode) return; } - if (!cp_getvar("width", CP_NUM, &screen_width)) + if (!cp_getvar("width", CP_NUM, &screen_width, 0)) screen_width = DEF_WIDTH; count = (screen_width - LEFT_WIDTH) / (DEV_WIDTH + 1); diff --git a/src/frontend/diff.c b/src/frontend/diff.c index f9ba13f9a..77a5b73ff 100644 --- a/src/frontend/diff.c +++ b/src/frontend/diff.c @@ -123,11 +123,11 @@ com_diff(wordlist *wl) wordlist *tw; char numbuf[BSIZE_SP], numbuf2[BSIZE_SP], numbuf3[BSIZE_SP], numbuf4[BSIZE_SP]; /* For printnum */ - if (!cp_getvar("diff_vntol", CP_REAL, &vntol)) + if (!cp_getvar("diff_vntol", CP_REAL, &vntol, 0)) vntol = 1.0e-6; - if (!cp_getvar("diff_abstol", CP_REAL, &abstol)) + if (!cp_getvar("diff_abstol", CP_REAL, &abstol, 0)) abstol = 1.0e-12; - if (!cp_getvar("diff_reltol", CP_REAL, &reltol)) + if (!cp_getvar("diff_reltol", CP_REAL, &reltol, 0)) reltol = 0.001; /* Let's try to be clever about defaults. This code is ugly. */ diff --git a/src/frontend/fourier.c b/src/frontend/fourier.c index 6908ed17b..5e86b7642 100644 --- a/src/frontend/fourier.c +++ b/src/frontend/fourier.c @@ -65,11 +65,11 @@ fourier(wordlist *wl, struct plot *current_plot) return 1; } - if (!cp_getvar("nfreqs", CP_NUM, &nfreqs) || nfreqs < 1) + if (!cp_getvar("nfreqs", CP_NUM, &nfreqs, 0) || nfreqs < 1) nfreqs = 10; - if (!cp_getvar("polydegree", CP_NUM, &polydegree) || polydegree < 0) + if (!cp_getvar("polydegree", CP_NUM, &polydegree, 0) || polydegree < 0) polydegree = 1; - if (!cp_getvar("fourgridsize", CP_NUM, &fourgridsize) || fourgridsize < 1) + if (!cp_getvar("fourgridsize", CP_NUM, &fourgridsize, 0) || fourgridsize < 1) fourgridsize = DEF_FOURGRIDSIZE; time = current_plot->pl_scale; diff --git a/src/frontend/hpgl.c b/src/frontend/hpgl.c index e327a7a9b..53565adc4 100644 --- a/src/frontend/hpgl.c +++ b/src/frontend/hpgl.c @@ -87,7 +87,7 @@ static int hcopygraphid; int GL_Init(void) { - if (!cp_getvar("hcopyscale", CP_STRING, psscale)) { + if (!cp_getvar("hcopyscale", CP_STRING, psscale, 32)) { scale = 1.0; } else { sscanf(psscale, "%lf", &scale); diff --git a/src/frontend/inp.c b/src/frontend/inp.c index b949b30ea..24214f356 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -200,7 +200,7 @@ inp_list(FILE *file, struct card *deck, struct card *extras, int type) file = cp_more; } - renumber = cp_getvar("renumber", CP_BOOL, NULL); + renumber = cp_getvar("renumber", CP_BOOL, NULL, 0); if (type == LS_LOGICAL) { top1: @@ -588,7 +588,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) cp_vset("pretemp", CP_REAL, &temperature_value); } if (ft_ngdebug) { - cp_getvar("pretemp", CP_REAL, &testemp); + cp_getvar("pretemp", CP_REAL, &testemp, 0); printf("test temperature %f\n", testemp); } @@ -600,7 +600,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) SetAnalyse("Prepare Deck", 0); #endif /* Now expand subcircuit macros and substitute numparams.*/ - if (!cp_getvar("nosubckt", CP_BOOL, NULL)) + if (!cp_getvar("nosubckt", CP_BOOL, NULL, 0)) if ((deck->nextcard = inp_subcktexpand(deck->nextcard)) == NULL) { line_free(realdeck, TRUE); line_free(deck->actualLine, TRUE); @@ -723,7 +723,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) } if (ciprefix(".meas", dd->line)) { - if (cp_getvar("autostop", CP_BOOL, NULL)) { + if (cp_getvar("autostop", CP_BOOL, NULL, 0)) { if (strstr(dd->line, " max ") || strstr(dd->line, " min ") || strstr(dd->line, " avg ") || @@ -876,7 +876,7 @@ inp_dodeck( /*PN FTESTATS*/ ft_curckt->FTEstats = TMALLOC(FTESTATistics, 1); } - noparse = cp_getvar("noparse", CP_BOOL, NULL); + noparse = cp_getvar("noparse", CP_BOOL, NULL, 0); /* We check preliminary for the scale option. This special processing @@ -944,12 +944,12 @@ inp_dodeck( out_init(); /* if_inpdeck() may return NULL upon error */ if (ckt) { - if (cp_getvar("warn", CP_NUM, &warn)) + if (cp_getvar("warn", CP_NUM, &warn, 0)) ckt->CKTsoaCheck = warn; else ckt->CKTsoaCheck = 0; - if (cp_getvar("maxwarns", CP_NUM, &maxwarns)) + if (cp_getvar("maxwarns", CP_NUM, &maxwarns, 0)) ckt->CKTsoaMaxWarns = maxwarns; else ckt->CKTsoaMaxWarns = 5; @@ -1017,7 +1017,7 @@ inp_dodeck( } /* Only print out netlist if brief is FALSE */ - if (!cp_getvar("brief", CP_BOOL, NULL)) { + if (!cp_getvar("brief", CP_BOOL, NULL, 0)) { /* output deck */ out_printf("\nProcessed Netlist\n"); out_printf("=================\n"); @@ -1137,7 +1137,7 @@ com_edit(wordlist *wl) bool inter, permfile; char buf[BSIZE_SP]; - if (!cp_getvar("interactive", CP_BOOL, NULL)) { + if (!cp_getvar("interactive", CP_BOOL, NULL, 0)) { fprintf(cp_err, "Warning: `edit' is disabled because 'interactive' has not been set.\n" " perhaps you want to 'set interactive'\n"); @@ -1357,7 +1357,7 @@ doedit(char *filename) { char buf[BSIZE_SP], buf2[BSIZE_SP], *editor; - if (cp_getvar("editor", CP_STRING, buf2)) { + if (cp_getvar("editor", CP_STRING, buf2, 512)) { editor = buf2; } else { if ((editor = getenv("EDITOR")) == NULL) { diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index c65c26336..8b8667f8a 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -491,7 +491,7 @@ ngspice_compat_mode(void) { char behaviour[80]; - if (cp_getvar("ngbehavior", CP_STRING, behaviour)) { + if (cp_getvar("ngbehavior", CP_STRING, behaviour, 80)) { if (strcasecmp(behaviour, "all") == 0) return COMPATMODE_ALL; if (strcasecmp(behaviour, "hs") == 0) @@ -599,7 +599,7 @@ inp_readall(FILE *fp, char *dir_name, bool comfile, bool intfile, bool *expr_w_t inp_fix_gnd_name(working); inp_chk_for_multi_in_vcvs(working, &rv. line_number); - if (cp_getvar("addcontrol", CP_BOOL, NULL)) + if (cp_getvar("addcontrol", CP_BOOL, NULL, 0)) inp_add_control_section(working, &rv . line_number); #ifndef XSPICE inp_poly_err(working); @@ -1144,7 +1144,7 @@ inp_pathresolve(const char *name) #if defined(__MINGW32__) || defined(_MSC_VER) /* If variable 'mingwpath' is set: convert mingw /d/... to d:/... */ - if (cp_getvar("mingwpath", CP_BOOL, NULL) && name[0] == DIR_TERM_LINUX && isalpha_c(name[1]) && name[2] == DIR_TERM_LINUX) { + if (cp_getvar("mingwpath", CP_BOOL, NULL, 0) && name[0] == DIR_TERM_LINUX && isalpha_c(name[1]) && name[2] == DIR_TERM_LINUX) { strcpy(buf, name); buf[0] = buf[1]; buf[1] = ':'; @@ -1158,7 +1158,7 @@ inp_pathresolve(const char *name) return copy(name); /* fail if this was an absolute filename or if there is no sourcepath var */ - if (is_absolute_pathname(name) || !cp_getvar("sourcepath", CP_LIST, &v)) + if (is_absolute_pathname(name) || !cp_getvar("sourcepath", CP_LIST, &v, 0)) return NULL; for (; v; v = v->va_next) { @@ -1512,7 +1512,7 @@ inp_add_control_section(struct card *deck, int *line_number) found_run = TRUE; } - if (cp_getvar("rawfile", CP_STRING, rawfile)) { + if (cp_getvar("rawfile", CP_STRING, rawfile, 1000)) { line = tprintf("write %s", rawfile); prev_card = insert_new_line(prev_card, line, (*line_number)++, 0); } @@ -1531,7 +1531,7 @@ inp_add_control_section(struct card *deck, int *line_number) if (op_line) deck = insert_new_line(deck, copy(op_line), (*line_number)++, 0); - if (cp_getvar("rawfile", CP_STRING, rawfile)) { + if (cp_getvar("rawfile", CP_STRING, rawfile, 1000)) { line = tprintf("write %s", rawfile); deck = insert_new_line(deck, line, (*line_number)++, 0); } diff --git a/src/frontend/measure.c b/src/frontend/measure.c index 7dea2d5a5..fff28e919 100644 --- a/src/frontend/measure.c +++ b/src/frontend/measure.c @@ -239,7 +239,7 @@ do_measure( } /* don't allow autostop if no .meas commands are given in the input file */ - if ((cp_getvar("autostop", CP_BOOL, NULL)) && (ft_curckt->ci_meas == NULL)) { + if ((cp_getvar("autostop", CP_BOOL, NULL, 0)) && (ft_curckt->ci_meas == NULL)) { fprintf(cp_err, "\nWarning: No .meas commands found!\n"); fprintf(cp_err, " Option autostop is not available, ignored!\n\n"); cp_remvar("autostop"); @@ -447,7 +447,7 @@ check_autostop(char* what) { bool flag = FALSE; - if (cp_getvar("autostop", CP_BOOL, NULL)) + if (cp_getvar("autostop", CP_BOOL, NULL, 0)) flag = do_measure(what, TRUE); return flag; diff --git a/src/frontend/misccoms.c b/src/frontend/misccoms.c index 04f3f30f4..de469ec68 100644 --- a/src/frontend/misccoms.c +++ b/src/frontend/misccoms.c @@ -45,7 +45,7 @@ com_quit(wordlist *wl) bool noask = (wl && wl->wl_word && 1 == sscanf(wl->wl_word, "%d", &exitcode)) || (wl && wl->wl_word && cieq(wl->wl_word, "noask")) || - !cp_getvar("askquit", CP_BOOL, NULL); + !cp_getvar("askquit", CP_BOOL, NULL, 0); /* update screen and reset terminal */ gr_clean(); diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index a9bc48664..454432307 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -359,7 +359,7 @@ nupa_done(void) if (nerrors) { bool is_interactive = FALSE; - if (cp_getvar("interactive", CP_BOOL, NULL)) + if (cp_getvar("interactive", CP_BOOL, NULL, 0)) is_interactive = TRUE; printf(" Copies=%d Evals=%d Placeholders=%ld Symbols=%d Errors=%d\n", linecountS, evalcountS, placeholder, dictsize, nerrors); diff --git a/src/frontend/nutinp.c b/src/frontend/nutinp.c index 4d09c8dee..7597dba3b 100644 --- a/src/frontend/nutinp.c +++ b/src/frontend/nutinp.c @@ -156,7 +156,7 @@ inp_nutsource(FILE *fp, bool comfile, char *filename) * fix the case before we do this but after we * deal with the commands. */ - if (!cp_getvar("nosubckt", CP_BOOL, NULL)) + if (!cp_getvar("nosubckt", CP_BOOL, NULL, 0)) deck->nextcard = inp_subcktexpand(deck->nextcard); deck->actualLine = realdeck; nutinp_dodeck(deck, tt, wl, FALSE, options, filename); diff --git a/src/frontend/outitf.c b/src/frontend/outitf.c index e4a56e5b4..f74e0e5d9 100644 --- a/src/frontend/outitf.c +++ b/src/frontend/outitf.c @@ -154,11 +154,11 @@ beginPlot(JOB *analysisPtr, CKTcircuit *circuitPtr, char *cktName, char *analNam /*end saj*/ /* Check to see if we want to print informational data. */ - if (cp_getvar("printinfo", CP_BOOL, NULL)) + if (cp_getvar("printinfo", CP_BOOL, NULL, 0)) fprintf(cp_err, "(debug printing enabled)\n"); /* Check to see if we want to save only interpolated data. */ - if (cp_getvar("interp", CP_BOOL, NULL)) { + if (cp_getvar("interp", CP_BOOL, NULL, 0)) { interpolated = TRUE; fprintf(cp_out, "Warning: Interpolated raw file data!\n\n"); } @@ -1292,7 +1292,7 @@ OUTerror(int flags, char *format, IFuid *names) char buf[BSIZE_SP], *s, *bptr; int nindex = 0; - if ((flags == ERR_INFO) && cp_getvar("printinfo", CP_BOOL, NULL)) + if ((flags == ERR_INFO) && cp_getvar("printinfo", CP_BOOL, NULL, 0)) return; for (m = msgs; m->flag; m++) @@ -1325,7 +1325,7 @@ OUTerrorf(int flags, const char *format, ...) struct mesg *m; va_list args; - if ((flags == ERR_INFO) && cp_getvar("printinfo", CP_BOOL, NULL)) + if ((flags == ERR_INFO) && cp_getvar("printinfo", CP_BOOL, NULL, 0)) return; for (m = msgs; m->flag; m++) diff --git a/src/frontend/plotting/agraf.c b/src/frontend/plotting/agraf.c index 435474fe5..5acf73ea7 100644 --- a/src/frontend/plotting/agraf.c +++ b/src/frontend/plotting/agraf.c @@ -58,7 +58,7 @@ ft_agraf(double *xlims, double *ylims, struct dvec *xscale, struct plot *plot, s /* Make sure the margin is correct */ omargin = margin; - novalue = cp_getvar("noasciiplotvalue", CP_BOOL, NULL); + novalue = cp_getvar("noasciiplotvalue", CP_BOOL, NULL, 0); if (!novalue && !vec_eq(xscale, vecs)) margin *= 2; else @@ -67,16 +67,16 @@ ft_agraf(double *xlims, double *ylims, struct dvec *xscale, struct plot *plot, s if ((xscale->v_gridtype == GRID_YLOG) || (xscale->v_gridtype == GRID_LOGLOG)) ylogscale = TRUE; - if (!cp_getvar("width", CP_NUM, &maxy)) + if (!cp_getvar("width", CP_NUM, &maxy, 0)) maxy = DEF_WIDTH; - if (!cp_getvar("height", CP_NUM, &height)) + if (!cp_getvar("height", CP_NUM, &height, 0)) height = DEF_HEIGHT; if (ft_nopage) nobreakp = TRUE; else - nobreakp = cp_getvar("nobreak", CP_BOOL, NULL); + nobreakp = cp_getvar("nobreak", CP_BOOL, NULL, 0); maxy -= (margin + FUDGE); maxx = xscale->v_length; diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index b9a26735d..1ff24fa01 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -77,7 +77,7 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab extrange = 0.05 * (ylims[1] - ylims[0]); - if (!cp_getvar("gnuplot_terminal", CP_STRING, terminal)) { + if (!cp_getvar("gnuplot_terminal", CP_STRING, terminal, sizeof(terminal))) { terminal_type = 1; } else { terminal_type = 1; @@ -85,11 +85,11 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab terminal_type = 2; } - if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth)) + if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth, 0)) linewidth = 1; if (linewidth < 1) linewidth = 1; - if (!cp_getvar("pointstyle", CP_STRING, pointstyle)) { + if (!cp_getvar("pointstyle", CP_STRING, pointstyle, sizeof(pointstyle))) { markers = FALSE; } else { if (cieq(pointstyle,"markers")) @@ -324,9 +324,9 @@ ft_writesimple(double *xlims, double *ylims, char *filename, char *title, char * NG_IGNORE(gridtype); NG_IGNORE(plottype); - appendwrite = cp_getvar("appendwrite", CP_BOOL, NULL); - singlescale = cp_getvar("wr_singlescale", CP_BOOL, NULL); - vecnames = cp_getvar("wr_vecnames", CP_BOOL, NULL); + appendwrite = cp_getvar("appendwrite", CP_BOOL, NULL, 0); + singlescale = cp_getvar("wr_singlescale", CP_BOOL, NULL, 0); + vecnames = cp_getvar("wr_vecnames", CP_BOOL, NULL, 0); /* Sanity checking. */ for (v = vecs, numVecs = 0; v; v = v->v_link2) diff --git a/src/frontend/plotting/graf.c b/src/frontend/plotting/graf.c index 3d069b350..8c862ee50 100644 --- a/src/frontend/plotting/graf.c +++ b/src/frontend/plotting/graf.c @@ -104,17 +104,17 @@ gr_init(double *xlims, double *ylims, /* The size of the screen. */ cur.plotno = 0; /* note: should do only once, maybe in gr_init_once */ - if (!cp_getvar("pointchars", CP_STRING, pointchars)) + if (!cp_getvar("pointchars", CP_STRING, pointchars, sizeof(pointchars))) (void) strcpy(pointchars, DEFPOINTCHARS); - if (!cp_getvar("ticmarks", CP_NUM, &graph->ticmarks)) { - if (cp_getvar("ticmarks", CP_BOOL, NULL)) + if (!cp_getvar("ticmarks", CP_NUM, &graph->ticmarks, 0)) { + if (cp_getvar("ticmarks", CP_BOOL, NULL, 0)) graph->ticmarks = 10; else graph->ticmarks = 0; } - if (cp_getvar("ticlist", CP_LIST, ticlist)) { + if (cp_getvar("ticlist", CP_LIST, ticlist, 0)) { wl = vareval("ticlist"); ticlist = wl_flatten(wl); graph->ticdata = readtics(ticlist); @@ -445,7 +445,7 @@ gr_pmsg(char *text) DevUpdate(); - if (cp_getvar("device", CP_STRING, buf) && !(strcmp("/dev/tty", buf) == 0)) + if (cp_getvar("device", CP_STRING, buf, sizeof(buf)) && !(strcmp("/dev/tty", buf) == 0)) fprintf(cp_err, "%s", text); else if (currentgraph->grid.xlabel) /* MW. grid.xlabel may be NULL */ diff --git a/src/frontend/plotting/plotcurv.c b/src/frontend/plotting/plotcurv.c index ce11525c9..768e9560d 100644 --- a/src/frontend/plotting/plotcurv.c +++ b/src/frontend/plotting/plotcurv.c @@ -41,7 +41,7 @@ ft_graf(struct dvec *v, struct dvec *xs, bool nostart) if (nostart) { degree = currentgraph->degree; } else { - if (!cp_getvar("polydegree", CP_NUM, °ree)) + if (!cp_getvar("polydegree", CP_NUM, °ree, 0)) degree = 1; currentgraph->degree = degree; } @@ -55,7 +55,7 @@ ft_graf(struct dvec *v, struct dvec *xs, bool nostart) return; } - if (!cp_getvar("gridsize", CP_NUM, &gridsize)) + if (!cp_getvar("gridsize", CP_NUM, &gridsize, 0)) gridsize = 0; if ((gridsize < 0) || (gridsize > 10000)) { @@ -325,7 +325,7 @@ plotinterval(struct dvec *v, double lo, double hi, register double *coeffs, int /* This is a problem -- how do we know what granularity to use? If * the guy cares about this he will use gridsize. */ - if (!cp_getvar("polysteps", CP_NUM, &steps)) + if (!cp_getvar("polysteps", CP_NUM, &steps, 0)) steps = GRANULARITY; incr = (hi - lo) / (double) (steps + 1); diff --git a/src/frontend/plotting/plotit.c b/src/frontend/plotting/plotit.c index 1f576cc2f..89307ad92 100644 --- a/src/frontend/plotting/plotit.c +++ b/src/frontend/plotting/plotit.c @@ -417,7 +417,7 @@ plotit(wordlist *wl, char *hcopy, char *devname) } if (!sameflag && !gfound) { - if (cp_getvar("gridstyle", CP_STRING, buf)) { + if (cp_getvar("gridstyle", CP_STRING, buf, sizeof(buf))) { if (eq(buf, "lingrid")) gtype = GRID_LIN; else if (eq(buf, "loglog")) @@ -480,7 +480,7 @@ plotit(wordlist *wl, char *hcopy, char *devname) } if (!sameflag && !pfound) { - if (cp_getvar("plotstyle", CP_STRING, buf)) { + if (cp_getvar("plotstyle", CP_STRING, buf, sizeof(buf))) { if (eq(buf, "linplot")) ptype = PLOT_LIN; else if (eq(buf, "noretraceplot")) diff --git a/src/frontend/plotting/xgraph.c b/src/frontend/plotting/xgraph.c index 216bd650b..ff40075bd 100644 --- a/src/frontend/plotting/xgraph.c +++ b/src/frontend/plotting/xgraph.c @@ -38,13 +38,13 @@ ft_xgraph(double *xlims, double *ylims, char *filename, char *title, char *xlabe return; } - if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth)) + if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth, 0)) linewidth = 1; if (linewidth < 1) linewidth = 1; - if (!cp_getvar("pointstyle", CP_STRING, pointstyle)) { + if (!cp_getvar("pointstyle", CP_STRING, pointstyle, sizeof(pointstyle))) { markers = FALSE; } else { if (cieq(pointstyle, "markers")) diff --git a/src/frontend/postcoms.c b/src/frontend/postcoms.c index 138d69dec..d24c2ca28 100644 --- a/src/frontend/postcoms.c +++ b/src/frontend/postcoms.c @@ -143,7 +143,7 @@ com_print(wordlist *wl) out_init(); if (!col) { - if (cp_getvar("width", CP_NUM, &i)) + if (cp_getvar("width", CP_NUM, &i, 0)) width = i; if (width < 60) width = 60; @@ -219,7 +219,7 @@ com_print(wordlist *wl) } //end if (v->v_rlength == 1) } // end for loop } else { /* Print in columns. */ - if (cp_getvar("width", CP_NUM, &i)) + if (cp_getvar("width", CP_NUM, &i, 0)) width = i; if (width < 40) width = 40; @@ -227,16 +227,16 @@ com_print(wordlist *wl) buf = TREALLOC(char, buf, width + 1); buf2 = TREALLOC(char, buf2, width + 1); } - if (cp_getvar("height", CP_NUM, &i)) + if (cp_getvar("height", CP_NUM, &i, 0)) height = i; if (height < 20) height = 20; - nobreak = cp_getvar("nobreak", CP_BOOL, NULL); + nobreak = cp_getvar("nobreak", CP_BOOL, NULL, 0); if (!nobreak && !ft_nopage) nobreak = FALSE; else nobreak = TRUE; - noprintscale = cp_getvar("noprintscale", CP_BOOL, NULL); + noprintscale = cp_getvar("noprintscale", CP_BOOL, NULL, 0); bv = vecs; nextpage: /* Make the first vector of every page be the scale... */ @@ -397,7 +397,7 @@ com_write(wordlist *wl) file = ft_rawfile; } - if (cp_getvar("filetype", CP_STRING, buf)) { + if (cp_getvar("filetype", CP_STRING, buf, sizeof(buf))) { if (eq(buf, "binary")) ascii = FALSE; else if (eq(buf, "ascii")) @@ -405,7 +405,7 @@ com_write(wordlist *wl) else fprintf(cp_err, "Warning: strange file type %s\n", buf); } - appendwrite = cp_getvar("appendwrite", CP_BOOL, NULL); + appendwrite = cp_getvar("appendwrite", CP_BOOL, NULL, 0); if (wl) names = ft_getpnames(wl, TRUE); diff --git a/src/frontend/postsc.c b/src/frontend/postsc.c index 79543e843..8c31d0a04 100644 --- a/src/frontend/postsc.c +++ b/src/frontend/postsc.c @@ -84,7 +84,7 @@ PS_Init(void) { char pswidth[30], psheight[30]; - if (!cp_getvar("hcopyscale", CP_STRING, psscale)) { + if (!cp_getvar("hcopyscale", CP_STRING, psscale, sizeof(psscale))) { scale = 1.0; } else { sscanf(psscale, "%lf", &scale); @@ -93,7 +93,7 @@ PS_Init(void) } dispdev->numlinestyles = NUMELEMS(linestyle); /* plot color */ - if (!cp_getvar("hcopypscolor", CP_NUM, &setbgcolor)) { + if (!cp_getvar("hcopypscolor", CP_NUM, &setbgcolor, 0)) { /* if not set, set plot to b&w and use line styles */ colorflag = 0; dispdev->numcolors = 2; @@ -102,11 +102,11 @@ PS_Init(void) /* get backgroung color and set plot to color */ colorflag = 1; dispdev->numcolors = 21; /* don't know what the maximum should be */ - cp_getvar("hcopypstxcolor", CP_NUM, &settxcolor); + cp_getvar("hcopypstxcolor", CP_NUM, &settxcolor, 0); } /* plot size */ - if (!cp_getvar("hcopywidth", CP_STRING, pswidth)) { + if (!cp_getvar("hcopywidth", CP_STRING, pswidth, sizeof( pswidth))) { dispdev->width = (int)(7.75 * 72.0 * scale); /* (8 1/2 - 3/4) * 72 */ } else { sscanf(pswidth, "%d", &(dispdev->width)); @@ -115,7 +115,7 @@ PS_Init(void) if (dispdev->width >= 10000) dispdev->width = 10000; } - if (!cp_getvar("hcopyheight", CP_STRING, psheight)) { + if (!cp_getvar("hcopyheight", CP_STRING, psheight, sizeof(psheight))) { dispdev->height = dispdev->width; } else { sscanf(psheight, "%d", &(dispdev->height)); @@ -135,9 +135,9 @@ PS_Init(void) * viewport.height = absolute.height - 2 * viewportyoff */ - if (!cp_getvar("hcopyfont", CP_STRING, psfont)) + if (!cp_getvar("hcopyfont", CP_STRING, psfont, sizeof(psfont))) strcpy(psfont, "Helvetica"); - if (!cp_getvar("hcopyfontsize", CP_STRING, psfontsize)) { + if (!cp_getvar("hcopyfontsize", CP_STRING, psfontsize, sizeof(psfontsize))) { fontsize = 10; fontwidth = 6; fontheight = 14; @@ -422,7 +422,7 @@ PS_SelectColor(int colorid) /* should be replaced by PS_DefineColor */ /* Extract the rgbcolor, format is: "rgb://" */ sprintf(colorN, "color%d", colorid); - if (cp_getvar(colorN, CP_STRING, colorstring)) { + if (cp_getvar(colorN, CP_STRING, colorstring, sizeof(colorstring))) { for (i = 0; colorstring[i]; i++) if (colorstring[i] == '/' || colorstring[i] == ':') colorstring[i] = ' '; diff --git a/src/frontend/rawfile.c b/src/frontend/rawfile.c index dfd8b4f4f..0ecf0c354 100644 --- a/src/frontend/rawfile.c +++ b/src/frontend/rawfile.c @@ -50,7 +50,7 @@ raw_write(char *name, struct plot *pl, bool app, bool binary) char buf[BSIZE_SP]; char *branch; - raw_padding = !cp_getvar("nopadding", CP_BOOL, NULL); + raw_padding = !cp_getvar("nopadding", CP_BOOL, NULL, 0); /* Why bother printing out an empty plot? */ if (!pl->pl_dvecs) { diff --git a/src/frontend/runcoms.c b/src/frontend/runcoms.c index d8cede126..59a4ea297 100644 --- a/src/frontend/runcoms.c +++ b/src/frontend/runcoms.c @@ -215,7 +215,7 @@ dosim( ww = wl_cons(copy(what), wl); } /* reset output file type according to variable given in spinit */ - if (cp_getvar("filetype", CP_STRING, buf)) { + if (cp_getvar("filetype", CP_STRING, buf, sizeof(buf))) { if (eq(buf, "binary")) ascii = FALSE; else if (eq(buf, "ascii")) diff --git a/src/frontend/runcoms2.c b/src/frontend/runcoms2.c index fe223ca3d..46003054b 100644 --- a/src/frontend/runcoms2.c +++ b/src/frontend/runcoms2.c @@ -91,7 +91,7 @@ com_resume(wordlist *wl) if (last_used_rawfile) dofile = TRUE; - if (cp_getvar("filetype", CP_STRING, buf)) { + if (cp_getvar("filetype", CP_STRING, buf, sizeof(buf))) { if (eq(buf, "binary")) ascii = FALSE; else if (eq(buf, "ascii")) diff --git a/src/frontend/spec.c b/src/frontend/spec.c index 69faa42cc..11db680d9 100644 --- a/src/frontend/spec.c +++ b/src/frontend/spec.c @@ -91,7 +91,7 @@ com_spec(wordlist *wl) { char window[BSIZE_SP]; double maxt = time[tlen-1]; - if (!cp_getvar("specwindow", CP_STRING, window)) + if (!cp_getvar("specwindow", CP_STRING, window, sizeof(window))) strcpy(window, "hanning"); if (eq(window, "none")) for (i = 0; i < tlen; i++) @@ -130,7 +130,7 @@ com_spec(wordlist *wl) } else if (eq(window, "blackman")) { int order; - if (!cp_getvar("specwindoworder", CP_NUM, &order)) + if (!cp_getvar("specwindoworder", CP_NUM, &order, 0)) order = 2; if (order < 2) /* only order 2 supported here */ order = 2; @@ -146,7 +146,7 @@ com_spec(wordlist *wl) } else if (eq(window, "gaussian")) { int order; double scale; - if (!cp_getvar("specwindoworder", CP_NUM, &order)) + if (!cp_getvar("specwindoworder", CP_NUM, &order, 0)) order = 2; if (order < 2) order = 2; @@ -237,7 +237,7 @@ com_spec(wordlist *wl) dc[i] += tdvec[i][k]*amp; } } - trace = cp_getvar("spectrace", CP_BOOL, NULL); + trace = cp_getvar("spectrace", CP_BOOL, NULL, 0); for (j = (startf == 0 ? 1 : 0); j < fpts; j++) { freq[j] = startf + j*stepf; if (trace) diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index 082cbea3e..8cf3a4e9e 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -213,18 +213,18 @@ inp_subcktexpand(struct card *deck) { struct card *c; wordlist *modnames = NULL; - if (!cp_getvar("substart", CP_STRING, start)) + if (!cp_getvar("substart", CP_STRING, start, sizeof(start))) strcpy(start, ".subckt"); - if (!cp_getvar("subend", CP_STRING, sbend)) + if (!cp_getvar("subend", CP_STRING, sbend, sizeof(sbend))) strcpy(sbend, ".ends"); - if (!cp_getvar("subinvoke", CP_STRING, invoke)) + if (!cp_getvar("subinvoke", CP_STRING, invoke, sizeof(invoke))) strcpy(invoke, "x"); - if (!cp_getvar("modelcard", CP_STRING, model)) + if (!cp_getvar("modelcard", CP_STRING, model, sizeof(model))) strcpy(model, ".model"); - if (!cp_getvar("modelline", CP_STRING, model)) + if (!cp_getvar("modelline", CP_STRING, model, sizeof(model))) strcpy(model, ".model"); - use_numparams = cp_getvar("numparams", CP_BOOL, NULL); + use_numparams = cp_getvar("numparams", CP_BOOL, NULL, 0); use_numparams = TRUE; diff --git a/src/frontend/terminal.c b/src/frontend/terminal.c index c37dd16d0..be21a4dd4 100644 --- a/src/frontend/terminal.c +++ b/src/frontend/terminal.c @@ -73,7 +73,7 @@ out_init(void) noprint = nopause = FALSE; - if (cp_getvar("moremode", CP_BOOL, NULL)) + if (cp_getvar("moremode", CP_BOOL, NULL, 0)) out_moremode = TRUE; else out_moremode = FALSE; @@ -99,9 +99,9 @@ out_init(void) #endif if (!xsize) - (void) cp_getvar("width", CP_NUM, &xsize); + (void) cp_getvar("width", CP_NUM, &xsize, 0); if (!ysize) - (void) cp_getvar("height", CP_NUM, &ysize); + (void) cp_getvar("height", CP_NUM, &ysize, 0); if (!xsize) xsize = DEF_SCRWIDTH; diff --git a/src/frontend/trannoise/1-f-code.c b/src/frontend/trannoise/1-f-code.c index d000619d9..9258d1890 100644 --- a/src/frontend/trannoise/1-f-code.c +++ b/src/frontend/trannoise/1-f-code.c @@ -119,7 +119,7 @@ trnoise_state_gen(struct trnoise_state *this, CKTcircuit *ckt) { if (this->top == 0) { - if (cp_getvar("notrnoise", CP_BOOL, NULL)) + if (cp_getvar("notrnoise", CP_BOOL, NULL, 0)) this -> NA = this -> TS = this -> NALPHA = this -> NAMP = this -> RTSAM = this -> RTSCAPT = this -> RTSEMT = 0.0; diff --git a/src/frontend/variable.c b/src/frontend/variable.c index 6652b053d..6ba60eee4 100644 --- a/src/frontend/variable.c +++ b/src/frontend/variable.c @@ -509,7 +509,7 @@ cp_remvar(char *varname) /* Determine the value of a variable. Fail if the variable is unset, * and if the type doesn't match, try and make it work... */ bool -cp_getvar(char *name, enum cp_types type, void *retval) +cp_getvar(char *name, enum cp_types type, void *retval, size_t rsize) { struct variable *v; struct variable *uv1; @@ -563,7 +563,12 @@ cp_getvar(char *name, enum cp_types type, void *retval) case CP_STRING: { /* Gotta be careful to have room. */ char *s = cp_unquote(v->va_string); cp_wstrip(s); - strcpy((char*) retval, s); + if (strlen(s) >= rsize - 1) { + fprintf(stderr, "Internal Error: string length for variable %s is limited to %d chars\n", v->va_name, rsize); + controlled_exit(EXIT_BAD); + } + else + strcpy((char*) retval, s); tfree(s); break; } diff --git a/src/include/ngspice/cpextern.h b/src/include/ngspice/cpextern.h index 70a69fccf..9955f0146 100644 --- a/src/include/ngspice/cpextern.h +++ b/src/include/ngspice/cpextern.h @@ -169,7 +169,7 @@ extern char *span_var_expr(char *t); /* var2.c */ extern void cp_vprint(void); -extern bool cp_getvar(char *name, enum cp_types type, void *retval); +extern bool cp_getvar(char *name, enum cp_types type, void *retval, size_t rsize); /* cpinterface.c etc -- stuff CP needs from FTE */ diff --git a/src/main.c b/src/main.c index 7e05180ba..1d5672c6c 100644 --- a/src/main.c +++ b/src/main.c @@ -1177,7 +1177,7 @@ main(int argc, char **argv) #elif defined(WaGauss) { unsigned int rseed = 66; - if (!cp_getvar("rndseed", CP_NUM, &rseed)) { + if (!cp_getvar("rndseed", CP_NUM, &rseed, 0)) { time_t acttime = time(NULL); rseed = (unsigned int) acttime; } diff --git a/src/maths/cmaths/cmath4.c b/src/maths/cmaths/cmath4.c index 5111314ff..fb27b2cd6 100644 --- a/src/maths/cmaths/cmath4.c +++ b/src/maths/cmaths/cmath4.c @@ -213,7 +213,7 @@ cx_interpolate(void *data, short int type, int length, int *newlength, short int *newlength = ns->v_length; d = alloc_d(ns->v_length); - if (!cp_getvar("polydegree", CP_NUM, °ree)) + if (!cp_getvar("polydegree", CP_NUM, °ree, 0)) degree = 1; for (base = 0; base < length; base += grouping) { @@ -248,7 +248,7 @@ cx_deriv(void *data, short int type, int length, int *newlength, short int *newt return (NULL); } - if (!cp_getvar("dpolydegree", CP_NUM, °ree)) + if (!cp_getvar("dpolydegree", CP_NUM, °ree, 0)) degree = 2; /* default quadratic */ n = degree + 1; @@ -615,9 +615,9 @@ cx_fft(void *data, short int type, int length, int *newlength, short int *newtyp win = TMALLOC(double, length); maxt = time[length-1]; - if (!cp_getvar("specwindow", CP_STRING, window)) + if (!cp_getvar("specwindow", CP_STRING, window, sizeof(window))) strcpy(window, "none"); - if (!cp_getvar("specwindoworder", CP_NUM, &order)) + if (!cp_getvar("specwindoworder", CP_NUM, &order, 0)) order = 2; if (order < 2) order = 2; diff --git a/src/maths/misc/randnumb.c b/src/maths/misc/randnumb.c index 5daad2094..6e8861289 100644 --- a/src/maths/misc/randnumb.c +++ b/src/maths/misc/randnumb.c @@ -77,7 +77,7 @@ void checkseed(void) int newseed; static int oldseed; /* printf("Enter checkseed()\n"); */ - if (cp_getvar("rndseed", CP_NUM, &newseed)) { + if (cp_getvar("rndseed", CP_NUM, &newseed, 0)) { if ((newseed > 0) && (oldseed != newseed)) { srand((unsigned int)newseed); TausSeed(); diff --git a/src/sharedspice.c b/src/sharedspice.c index f50108d40..2ce0da9dd 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -743,7 +743,7 @@ bot: #elif defined (WaGauss) { unsigned int rseed = 66; - if (!cp_getvar("rndseed", CP_NUM, &rseed)) { + if (!cp_getvar("rndseed", CP_NUM, &rseed, 0)) { time_t acttime = time(NULL); rseed = (unsigned int) acttime; } @@ -1114,7 +1114,7 @@ sh_vfprintf(FILE *f, const char *fmt, va_list args) } /* add / to escape characters, if 'set addescape' is called in .spiceinit */ - if (cp_getvar("addescape", CP_BOOL, NULL)) { + if (cp_getvar("addescape", CP_BOOL, NULL, 0)) { size_t escapes; const char * const escape_chars = "$[]\"\\"; char *s = p; diff --git a/src/spicelib/analysis/cktdojob.c b/src/spicelib/analysis/cktdojob.c index fc52981bb..5c87b2101 100644 --- a/src/spicelib/analysis/cktdojob.c +++ b/src/spicelib/analysis/cktdojob.c @@ -79,7 +79,7 @@ CKTdoJob(CKTcircuit *ckt, int reset, TSKtask *task) may be overridden by 'set xtrtol=newval' */ if (ckt->CKTadevFlag && (ckt->CKTtrtol > 1)) { int newtol; - if (cp_getvar("xtrtol", CP_NUM, &newtol)) { + if (cp_getvar("xtrtol", CP_NUM, &newtol, 0)) { printf("Override trtol to %d for xspice 'A' devices\n", newtol); ckt->CKTtrtol = newtol; } diff --git a/src/spicelib/analysis/cktsetup.c b/src/spicelib/analysis/cktsetup.c index 8804f24c4..3242944e1 100644 --- a/src/spicelib/analysis/cktsetup.c +++ b/src/spicelib/analysis/cktsetup.c @@ -63,7 +63,7 @@ CKTsetup(CKTcircuit *ckt) matrix = ckt->CKTmatrix; #ifdef USE_OMP - if (!cp_getvar("num_threads", CP_NUM, &nthreads)) + if (!cp_getvar("num_threads", CP_NUM, &nthreads, 0)) nthreads = 2; omp_set_num_threads(nthreads); diff --git a/src/spicelib/analysis/noisean.c b/src/spicelib/analysis/noisean.c index cce09b792..524e2feef 100644 --- a/src/spicelib/analysis/noisean.c +++ b/src/spicelib/analysis/noisean.c @@ -123,7 +123,7 @@ NOISEan (CKTcircuit *ckt, int restart) data->freq = job->NstartFreq; data->outNoiz = 0.0; data->inNoise = 0.0; - data->squared = cp_getvar("sqrnoise", CP_BOOL, NULL) ? 1 : 0; + data->squared = cp_getvar("sqrnoise", CP_BOOL, NULL, 0) ? 1 : 0; /* the current front-end needs the namelist to be fully declared before an OUTpBeginplot */ diff --git a/src/spicelib/devices/bsim3/b3par.c b/src/spicelib/devices/bsim3/b3par.c index c9c7ddfc1..35aae2535 100644 --- a/src/spicelib/devices/bsim3/b3par.c +++ b/src/spicelib/devices/bsim3/b3par.c @@ -28,7 +28,7 @@ IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/bsim3v0/b3v0par.c b/src/spicelib/devices/bsim3v0/b3v0par.c index 431ed2309..8fe314af7 100644 --- a/src/spicelib/devices/bsim3v0/b3v0par.c +++ b/src/spicelib/devices/bsim3v0/b3v0par.c @@ -20,7 +20,7 @@ BSIM3v0param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/bsim3v1/b3v1par.c b/src/spicelib/devices/bsim3v1/b3v1par.c index f29c1fbc6..2c58743ef 100644 --- a/src/spicelib/devices/bsim3v1/b3v1par.c +++ b/src/spicelib/devices/bsim3v1/b3v1par.c @@ -26,7 +26,7 @@ BSIM3v1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/bsim3v32/b3v32par.c b/src/spicelib/devices/bsim3v32/b3v32par.c index 425eb4489..83f1b4a61 100644 --- a/src/spicelib/devices/bsim3v32/b3v32par.c +++ b/src/spicelib/devices/bsim3v32/b3v32par.c @@ -25,7 +25,7 @@ BSIM3v32param (int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/bsim4/b4par.c b/src/spicelib/devices/bsim4/b4par.c index c37144932..702e81c7b 100644 --- a/src/spicelib/devices/bsim4/b4par.c +++ b/src/spicelib/devices/bsim4/b4par.c @@ -78,7 +78,7 @@ IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/bsim4v5/b4v5par.c b/src/spicelib/devices/bsim4v5/b4v5par.c index 12883bd02..a75f7217e 100644 --- a/src/spicelib/devices/bsim4v5/b4v5par.c +++ b/src/spicelib/devices/bsim4v5/b4v5par.c @@ -32,7 +32,7 @@ IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/bsim4v6/b4v6par.c b/src/spicelib/devices/bsim4v6/b4v6par.c index 8da55ef2a..a3ff5023d 100644 --- a/src/spicelib/devices/bsim4v6/b4v6par.c +++ b/src/spicelib/devices/bsim4v6/b4v6par.c @@ -34,7 +34,7 @@ IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/bsim4v7/b4v7par.c b/src/spicelib/devices/bsim4v7/b4v7par.c index ea503747f..f152f8df6 100644 --- a/src/spicelib/devices/bsim4v7/b4v7par.c +++ b/src/spicelib/devices/bsim4v7/b4v7par.c @@ -34,7 +34,7 @@ IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/bsimsoi/b4soipar.c b/src/spicelib/devices/bsimsoi/b4soipar.c index 6f027524b..3bd5bce75 100644 --- a/src/spicelib/devices/bsimsoi/b4soipar.c +++ b/src/spicelib/devices/bsimsoi/b4soipar.c @@ -34,7 +34,7 @@ IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) diff --git a/src/spicelib/devices/cap/capparam.c b/src/spicelib/devices/cap/capparam.c index 003ebc2bb..0e030ceef 100644 --- a/src/spicelib/devices/cap/capparam.c +++ b/src/spicelib/devices/cap/capparam.c @@ -24,7 +24,7 @@ CAPparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) { diff --git a/src/spicelib/devices/dio/dioparam.c b/src/spicelib/devices/dio/dioparam.c index 5585a06e3..fc81b17cc 100644 --- a/src/spicelib/devices/dio/dioparam.c +++ b/src/spicelib/devices/dio/dioparam.c @@ -25,7 +25,7 @@ DIOparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) { diff --git a/src/spicelib/devices/hisim2/hsm2par.c b/src/spicelib/devices/hisim2/hsm2par.c index a8fe25747..6e84d115d 100644 --- a/src/spicelib/devices/hisim2/hsm2par.c +++ b/src/spicelib/devices/hisim2/hsm2par.c @@ -73,7 +73,7 @@ int HSM2param( NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch (param) { diff --git a/src/spicelib/devices/hisimhv1/hsmhvpar.c b/src/spicelib/devices/hisimhv1/hsmhvpar.c index 24388523d..3ace52ccc 100644 --- a/src/spicelib/devices/hisimhv1/hsmhvpar.c +++ b/src/spicelib/devices/hisimhv1/hsmhvpar.c @@ -34,7 +34,7 @@ int HSMHVparam( NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch (param) { diff --git a/src/spicelib/devices/hisimhv2/hsmhv2par.c b/src/spicelib/devices/hisimhv2/hsmhv2par.c index a3fe1400b..be803e1e5 100644 --- a/src/spicelib/devices/hisimhv2/hsmhv2par.c +++ b/src/spicelib/devices/hisimhv2/hsmhv2par.c @@ -76,7 +76,7 @@ int HSMHV2param( NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch (param) { diff --git a/src/spicelib/devices/mos1/mos1par.c b/src/spicelib/devices/mos1/mos1par.c index ecd400918..3ae4681fd 100644 --- a/src/spicelib/devices/mos1/mos1par.c +++ b/src/spicelib/devices/mos1/mos1par.c @@ -25,7 +25,7 @@ MOS1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) { diff --git a/src/spicelib/devices/mos2/mos2par.c b/src/spicelib/devices/mos2/mos2par.c index f09259747..a818f7602 100644 --- a/src/spicelib/devices/mos2/mos2par.c +++ b/src/spicelib/devices/mos2/mos2par.c @@ -26,7 +26,7 @@ MOS2param(int param, IFvalue *value, GENinstance *inst, NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) { diff --git a/src/spicelib/devices/mos3/mos3par.c b/src/spicelib/devices/mos3/mos3par.c index 6a5320430..dea7b2421 100644 --- a/src/spicelib/devices/mos3/mos3par.c +++ b/src/spicelib/devices/mos3/mos3par.c @@ -25,7 +25,7 @@ MOS3param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) { diff --git a/src/spicelib/devices/res/resparam.c b/src/spicelib/devices/res/resparam.c index 1385a71b9..87420740d 100644 --- a/src/spicelib/devices/res/resparam.c +++ b/src/spicelib/devices/res/resparam.c @@ -21,7 +21,7 @@ RESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) { diff --git a/src/spicelib/devices/vdmos/vdmospar.c b/src/spicelib/devices/vdmos/vdmospar.c index a1f741ae6..9238fc8b6 100644 --- a/src/spicelib/devices/vdmos/vdmospar.c +++ b/src/spicelib/devices/vdmos/vdmospar.c @@ -25,7 +25,7 @@ VDMOSparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; switch(param) { diff --git a/src/spicelib/parser/inpgmod.c b/src/spicelib/parser/inpgmod.c index 8a68dceb1..f5c33031d 100644 --- a/src/spicelib/parser/inpgmod.c +++ b/src/spicelib/parser/inpgmod.c @@ -226,7 +226,7 @@ INPgetModBin(CKTcircuit *ckt, char *name, INPmodel **model, INPtables *tab, char static char *model_tokens[] = { "lmin", "lmax", "wmin", "wmax" }; double scale; - if (!cp_getvar("scale", CP_REAL, &scale)) + if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; *model = NULL;