.csparam: Add some safeguarding against wrong input and crash,
allow multiple parameters in a .csparam row (like .param).
This commit is contained in:
parent
ba2facc718
commit
3071cdd2d5
|
|
@ -890,23 +890,35 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
|
||||||
/* handle .if ... .elseif ... .else ... .endif statements. */
|
/* handle .if ... .elseif ... .else ... .endif statements. */
|
||||||
dotifeval(deck);
|
dotifeval(deck);
|
||||||
|
|
||||||
|
/* get csparams and create vectors, available
|
||||||
|
in plot 'const' of a .control section */
|
||||||
for (dd = deck; dd; dd = dd->nextcard) {
|
for (dd = deck; dd; dd = dd->nextcard) {
|
||||||
/* get csparams and create vectors, being
|
|
||||||
available in .control section, in plot 'const' */
|
|
||||||
if (ciprefix(".csparam", dd->line)) {
|
if (ciprefix(".csparam", dd->line)) {
|
||||||
wordlist *wlist = NULL;
|
wordlist *wlist = NULL;
|
||||||
char *cstoken[3];
|
char *cstoken[3];
|
||||||
int i;
|
int i;
|
||||||
dd->line[0] = '*';
|
dd->line[0] = '*';
|
||||||
s = skip_ws(dd->line + 8);
|
s = skip_ws(dd->line + 8);
|
||||||
cstoken[0] = gettok_char(&s, '=', FALSE, FALSE);
|
while (s && *s) {
|
||||||
cstoken[1] = gettok_char(&s, '=', TRUE, FALSE);
|
cstoken[0] = gettok_char(&s, '=', FALSE, FALSE);
|
||||||
cstoken[2] = gettok(&s);
|
cstoken[1] = gettok_char(&s, '=', TRUE, FALSE);
|
||||||
for (i = 3; --i >= 0; ) {
|
cstoken[2] = gettok(&s);
|
||||||
wlist = wl_cons(cstoken[i], wlist);
|
/* guard against buggy input line */
|
||||||
|
if (!cstoken[0] || !cstoken[1] || !cstoken[2] || strchr(cstoken[2],'=')) {
|
||||||
|
tfree(cstoken[0]);
|
||||||
|
tfree(cstoken[1]);
|
||||||
|
tfree(cstoken[2]);
|
||||||
|
fprintf(stderr, "Warning: bad csparam definition, skipped!\n");
|
||||||
|
fprintf(stderr, " in line %d, .%s\n\n", dd->linenum, dd->line + 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (i = 3; --i >= 0; ) {
|
||||||
|
wlist = wl_cons(cstoken[i], wlist);
|
||||||
|
}
|
||||||
|
com_let(wlist);
|
||||||
|
wl_free(wlist);
|
||||||
|
wlist = NULL;
|
||||||
}
|
}
|
||||||
com_let(wlist);
|
|
||||||
wl_free(wlist);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue