Browse Source

cleanup getlims() and plug a memory leak

rlar 15 years ago
parent
commit
27f1d7bb45
  1. 4
      ChangeLog
  2. 93
      src/frontend/plotting/plotit.c

4
ChangeLog

@ -1,3 +1,7 @@
2011-07-24 Robert Larice
* src/frontend/plotting/plotit.c :
cleanup getlims() and plug a memory leak
2011-07-24 Robert Larice 2011-07-24 Robert Larice
* src/xspice/ipc/ipcstdio.c : * src/xspice/ipc/ipcstdio.c :
(int) cast, where size can be expected to be small enough (int) cast, where size can be expected to be small enough

93
src/frontend/plotting/plotit.c

@ -30,54 +30,69 @@ static bool sameflag;
static double * static double *
getlims(wordlist *wl, char *name, int number) getlims(wordlist *wl, char *name, int number)
{ {
double *d, *td;
double *d;
wordlist *beg, *wk; wordlist *beg, *wk;
char *ss;
int n; int n;
if(number < 1) if(number < 1)
return NULL; return NULL;
for (beg = wl; beg; beg = beg->wl_next) {
if (eq(beg->wl_word, name)) {
if (beg == wl) {
fprintf(cp_err,
"Syntax error: looking for plot parameters \"%s\".\n",
name);
return (NULL);
}
wk = beg;
d = TMALLOC(double, number);
for (n = 0; n < number; n++) {
wk = wk->wl_next;
if (!wk) {
fprintf(cp_err,
"Syntax error: not enough parameters for \"%s\".\n",
name);
return (NULL);
}
ss = wk->wl_word;
td = ft_numparse(&ss, FALSE);
if (td == NULL)
goto bad;
d[n] = *td;
}
for (beg = wl; beg; beg = beg->wl_next)
if (eq(beg->wl_word, name))
break;
if (beg->wl_prev)
beg->wl_prev->wl_next = wk->wl_next;
if (wk->wl_next) {
wk->wl_next->wl_prev = beg->wl_prev;
wk->wl_next = NULL;
}
if (beg != wl_root)
wl_free(beg);
return (d);
if(!beg)
return NULL;
if (beg == wl) {
fprintf(cp_err,
"Syntax error: looking for plot parameters \"%s\".\n", name);
return NULL;
}
wk = beg;
d = TMALLOC(double, number);
for (n = 0; n < number; n++) {
char *ss;
double *td;
wk = wk->wl_next;
if (!wk) {
fprintf(cp_err,
"Syntax error: not enough parameters for \"%s\".\n", name);
txfree(d);
return NULL;
}
ss = wk->wl_word;
td = ft_numparse(&ss, FALSE);
if (!td) {
fprintf(cp_err,
"Syntax error: bad parameters for \"%s\".\n", name);
txfree(d);
return NULL;
} }
d[n] = *td;
} }
return (NULL);
bad:
fprintf(cp_err, "Syntax error: bad parameters for \"%s\".\n", name);
return (NULL);
if (beg->wl_prev)
beg->wl_prev->wl_next = wk->wl_next;
if (wk->wl_next) {
wk->wl_next->wl_prev = beg->wl_prev;
wk->wl_next = NULL;
}
if (beg != wl_root)
wl_free(beg);
return d;
} }

Loading…
Cancel
Save