From 62afa50a1c1fa87201689ca12b274ac7d0e4ea4f Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 24 Jul 2010 14:27:47 +0000 Subject: [PATCH] fix dangerous things, potential bugs, at least for big endian machines --- ChangeLog | 15 +++++++++++++++ src/frontend/inp.c | 3 +-- src/frontend/spiceif.c | 8 ++++++-- src/frontend/variable.c | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9776ead09..1d0ec402f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-07-24 Robert Larice + fix dangerous things, potential bugs, at least for big endian machines + * src/frontend/inp.c , + a bool (unsigned char) and an int have been mixed, + and the address of the thing was taken. + should fail on a big endian machine + * src/frontend/spiceif.c , + the value of an union, made of a bool (unsigned char), an int, etc, + is silently cast into an int. + This can introduce stack noise, in the CP_BOOL case + * src/frontend/variable.c : + a `variable' is created with type CP_NUM, + but only bool was initialized. + This can introduce stack noise. + 2010-07-24 Robert Larice * src/include/onedev.h , * src/include/twodev.h : diff --git a/src/frontend/inp.c b/src/frontend/inp.c index ff0bf1759..cdfcaceaa 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -697,7 +697,6 @@ inp_dodeck( wordlist *wl; bool noparse, ii; int print_listing; - static int one; /* First throw away any old error messages there might be and fix the case of the lines. */ @@ -882,7 +881,7 @@ inp_dodeck( } */ for (eev = ct->ci_vars; eev; eev = eev->va_next) { - one = 1; + bool one = TRUE; /* FIXME, actually eev->va_bool should be TRUE anyway */ switch (eev->va_type) { case CP_BOOL: if_option(ct->ci_ckt, eev->va_name, diff --git a/src/frontend/spiceif.c b/src/frontend/spiceif.c index ef651c14c..65019f9fd 100644 --- a/src/frontend/spiceif.c +++ b/src/frontend/spiceif.c @@ -472,8 +472,12 @@ if_option(CKTcircuit *ckt, char *name, enum cp_types type, void *value) goto badtype; break; case IF_FLAG: - /* Do nothing. */ - pval.iValue = *((int *) value); + if (type == CP_BOOL) + pval.iValue = *((bool *) value) ? 1 : 0; + else if (type == CP_NUM) /* FIXME, shall we allow this ? */ + pval.iValue = *((int *) value); + else + goto badtype; break; default: fprintf(cp_err, diff --git a/src/frontend/variable.c b/src/frontend/variable.c index 8b41d69fd..37e7b8fc5 100644 --- a/src/frontend/variable.c +++ b/src/frontend/variable.c @@ -449,7 +449,7 @@ cp_remvar(char *varname) ZERO(v, struct variable); v->va_name = copy(varname); v->va_type = CP_NUM; - v->va_bool = 0; + v->va_num = 0; found = FALSE; }