From 2c0144a849b317a9dc6547ba487cf43a60251512 Mon Sep 17 00:00:00 2001 From: rlar Date: Fri, 5 Aug 2011 19:29:57 +0000 Subject: [PATCH] rewrite to fix potential (actuall impossible) usage of variable `c' --- ChangeLog | 4 +++ src/maths/cmaths/cmath2.c | 57 ++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index ccb16fb52..44184971b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-08-05 Robert Larice + * src/maths/cmaths/cmath2.c : + rewrite to fix potential (actuall impossible) usage of variable `c' + 2011-08-05 Robert Larice * src/spicelib/parser/inp2m.c : fix warning of potential (actuall impossible) usage of uninitialized node5..7 diff --git a/src/maths/cmaths/cmath2.c b/src/maths/cmaths/cmath2.c index 8ab3d9963..619530e58 100644 --- a/src/maths/cmaths/cmath2.c +++ b/src/maths/cmaths/cmath2.c @@ -325,41 +325,42 @@ cx_sgauss(void *data, short int type, int length, int *newlength, short int *new void *cx_avg(void *data, short int type, int length, int *newlength, short int *newtype) { - ngcomplex_t *c; - double *d = NULL, sum_real = 0.0,sum_imag = 0.0; - ngcomplex_t *cc = (ngcomplex_t *) data; - double *dd = (double *) data; + double sum_real = 0.0, sum_imag = 0.0; int i; if (type == VF_REAL) { - d = alloc_d(length); + + double *d = alloc_d(length); + double *dd = (double *) data; + *newtype = VF_REAL; + *newlength = length; + + for (i = 0; i < length; i++) { + sum_real += dd[i]; + d[i] = sum_real / (double)(i+1); + } + + return ((void *) d); + } else { - c = alloc_c(length); + + ngcomplex_t *c = alloc_c(length); + ngcomplex_t *cc = (ngcomplex_t *) data; + *newtype = VF_COMPLEX; - } - *newlength = length; + *newlength = length; + + for (i = 0; i < length; i++) { + sum_real += realpart(&cc[i]); + realpart(&c[i]) = sum_real / (double)(i+1); + + sum_imag += imagpart(&cc[i]); + imagpart(&c[i]) = sum_imag / (double)(i+1); + } + + return ((void *) c); - if (type == VF_COMPLEX) - { - for (i = 0; i < length; i++) - { - sum_real= sum_real + realpart(&cc[i]); - realpart(&c[i]) = sum_real / (double)(i+1); - - sum_imag = sum_imag + imagpart(&cc[i]); - imagpart(&c[i]) = sum_imag / (double)(i+1); - } - return ((char *) c); - } - else - { //VF_REAL - for (i = 0; i < length; i++) - { - sum_real= sum_real + dd[i]; - d[i] = sum_real / (double)(i+1); - } - return ((char *) d); } }