Browse Source

Fixed an error in variable.c that caused a segmentation fault and updated files for rework-13

pre-master-46
pnenzi 26 years ago
parent
commit
a718fb27f5
  1. 2
      configure.in
  2. 37
      src/frontend/variable.c
  3. 22
      tests/fourbitadder.out

2
configure.in

@ -5,7 +5,7 @@ dnl Create a configuration header
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
dnl Initialize automake stuff dnl Initialize automake stuff
AM_INIT_AUTOMAKE(ng-spice-rework,12)
AM_INIT_AUTOMAKE(ng-spice-rework,13)
dnl --enable-ansi : try to force --ansi option to the compiler dnl --enable-ansi : try to force --ansi option to the compiler

37
src/frontend/variable.c

@ -89,13 +89,15 @@ cp_vset(char *varname, char type, char *value)
int i; int i;
bool alreadythere = FALSE; bool alreadythere = FALSE;
char* copyvarname; char* copyvarname;
/* varname = cp_unquote(varname); DG: Memory leak old varname is lost*/
copyvarname= cp_unquote(varname);
strcpy(varname,copyvarname);
tfree(copyvarname);
/* varname = cp_unquote(varname); DG: Memory leak old varname is lost*/
copyvarname = cp_unquote(varname);
w = NULL; w = NULL;
for (v = variables; v; v = v->va_next) { for (v = variables; v; v = v->va_next) {
if (eq(varname, v->va_name)) {
if (eq(copyvarname, v->va_name)) {
alreadythere = TRUE; alreadythere = TRUE;
break; break;
} }
@ -103,13 +105,13 @@ cp_vset(char *varname, char type, char *value)
} }
if (!v) { if (!v) {
v = alloc(struct variable); v = alloc(struct variable);
v->va_name = copy(varname);
v->va_name = copy(copyvarname);
v->va_next = NULL; v->va_next = NULL;
} }
switch (type) { switch (type) {
case VT_BOOL: case VT_BOOL:
if (* ((bool *) value) == FALSE) { if (* ((bool *) value) == FALSE) {
cp_remvar(varname);
cp_remvar(copyvarname);
return; return;
} else } else
v->va_bool = TRUE; v->va_bool = TRUE;
@ -143,21 +145,21 @@ cp_vset(char *varname, char type, char *value)
* recognise these special variables: noglob, nonomatch, history, * recognise these special variables: noglob, nonomatch, history,
* echo, noclobber, prompt, and verbose. cp_remvar looks for these * echo, noclobber, prompt, and verbose. cp_remvar looks for these
* variables too. The host program will get any others. */ * variables too. The host program will get any others. */
if (eq(varname, "noglob"))
if (eq(copyvarname, "noglob"))
cp_noglob = TRUE; cp_noglob = TRUE;
else if (eq(varname, "nonomatch"))
else if (eq(copyvarname, "nonomatch"))
cp_nonomatch = TRUE; cp_nonomatch = TRUE;
else if (eq(varname, "history") && (type == VT_NUM))
else if (eq(copyvarname, "history") && (type == VT_NUM))
cp_maxhistlength = v->va_num; cp_maxhistlength = v->va_num;
else if (eq(varname, "history") && (type == VT_REAL))
else if (eq(copyvarname, "history") && (type == VT_REAL))
cp_maxhistlength = v->va_real; cp_maxhistlength = v->va_real;
else if (eq(varname, "noclobber"))
else if (eq(copyvarname, "noclobber"))
cp_noclobber = TRUE; cp_noclobber = TRUE;
else if (eq(varname, "prompt") && (type == VT_STRING))
else if (eq(copyvarname, "prompt") && (type == VT_STRING))
cp_promptstring = copy(v->va_string); cp_promptstring = copy(v->va_string);
else if (eq(varname, "ignoreeof"))
else if (eq(copyvarname, "ignoreeof"))
cp_ignoreeof = TRUE; cp_ignoreeof = TRUE;
else if (eq(varname, "cpdebug")) {
else if (eq(copyvarname, "cpdebug")) {
cp_debug = TRUE; cp_debug = TRUE;
#ifndef CPDEBUG #ifndef CPDEBUG
fprintf(cp_err, fprintf(cp_err,
@ -202,7 +204,7 @@ cp_vset(char *varname, char type, char *value)
alreadythere = FALSE; alreadythere = FALSE;
if (ft_curckt) { if (ft_curckt) {
for (u = ft_curckt->ci_vars; u; u = u->va_next) for (u = ft_curckt->ci_vars; u; u = u->va_next)
if (eq(varname, u->va_name)) {
if (eq(copyvarname, u->va_name)) {
alreadythere = TRUE; alreadythere = TRUE;
break; break;
} }
@ -220,13 +222,14 @@ cp_vset(char *varname, char type, char *value)
case US_NOSIMVAR: case US_NOSIMVAR:
/* What do you do? */ /* What do you do? */
tfree(v); tfree(v);
break; break;
default: default:
fprintf(cp_err, "cp_vset: Internal Error: bad US val %d\n", i); fprintf(cp_err, "cp_vset: Internal Error: bad US val %d\n", i);
break; break;
} }
tfree(copyvarname);
return; return;
} }

22
tests/fourbitadder.out

@ -286,17 +286,17 @@ Index time v(1)
1 6.000000e-13 1.800000e-04 1 6.000000e-13 1.800000e-04
2 7.422315e-13 2.226694e-04 2 7.422315e-13 2.226694e-04
3 1.026694e-12 3.080083e-04 3 1.026694e-12 3.080083e-04
4 1.595620e-12 4.786860e-04
5 2.733472e-12 8.200415e-04
6 5.009175e-12 1.502753e-03
7 9.560581e-12 2.868174e-03
8 1.866339e-11 5.599018e-03
9 3.686902e-11 1.106071e-02
10 7.328027e-11 2.198408e-02
11 1.332803e-10 3.998408e-02
12 1.932803e-10 5.798408e-02
13 2.532803e-10 7.598408e-02
14 3.132803e-10 9.398408e-02
4 1.595620e-12 4.786861e-04
5 2.733472e-12 8.200417e-04
6 5.009176e-12 1.502753e-03
7 9.560584e-12 2.868175e-03
8 1.866340e-11 5.599020e-03
9 3.686903e-11 1.106071e-02
10 7.328029e-11 2.198409e-02
11 1.332803e-10 3.998409e-02
12 1.932803e-10 5.798409e-02
13 2.532803e-10 7.598409e-02
14 3.132803e-10 9.398409e-02
15 3.732803e-10 1.119841e-01 15 3.732803e-10 1.119841e-01
16 4.332803e-10 1.299841e-01 16 4.332803e-10 1.299841e-01
17 4.932803e-10 1.479841e-01 17 4.932803e-10 1.479841e-01

Loading…
Cancel
Save