From 90dd4f8bb94668598e46e473077da444a2166815 Mon Sep 17 00:00:00 2001 From: Pierre Blanchard Date: Tue, 15 Oct 2024 09:48:30 +0000 Subject: [PATCH 1/4] Fix errors reported by cppcheck in gencoef Error: uninitialized variables Fix: Only use mpfr_zinit when mpfr_t already initialized Note: The use of mpfr_zinit is inconsistent anyway. Gencoef needs a big cleanup and possibly porting to CMake --- src/gencoef/gencoef.c | 11 +++++------ src/gencoef/simplexfr.c | 15 ++++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gencoef/gencoef.c b/src/gencoef/gencoef.c index 87ea348e..c7e1b200 100644 --- a/src/gencoef/gencoef.c +++ b/src/gencoef/gencoef.c @@ -194,13 +194,12 @@ int main(int argc, char **argv) mpfr_zinit(result[i]); } - mpfr_t fra, frb, frc, frd, fre; + mpfr_t fra, frb, frc, frd; - mpfr_zinit(fra); - mpfr_zinit(frb); - mpfr_zinit(frc); - mpfr_zinit(frd); - mpfr_zinit(fre); + mpfr_init(fra); + mpfr_init(frb); + mpfr_init(frc); + mpfr_init(frd); for(i=0;i Date: Tue, 15 Oct 2024 12:55:37 +0000 Subject: [PATCH 2/4] Fix errors reported by cppcheck in src/libm/sleefsp.c Error: integer overflow Fix: Use appropriate intermediate type. UL should be big enough on all platforms. --- src/libm/sleefsp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libm/sleefsp.c b/src/libm/sleefsp.c index 7d53b573..1f80522e 100644 --- a/src/libm/sleefsp.c +++ b/src/libm/sleefsp.c @@ -53,11 +53,11 @@ static INLINE CONST float fabsfk(float x) { } static INLINE CONST float mulsignf(float x, float y) { - return intBitsToFloat(floatToRawIntBits(x) ^ (floatToRawIntBits(y) & (1 << 31))); + return intBitsToFloat(floatToRawIntBits(x) ^ (floatToRawIntBits(y) & 0x80000000U)); } static INLINE CONST float copysignfk(float x, float y) { - return intBitsToFloat((floatToRawIntBits(x) & ~(1 << 31)) ^ (floatToRawIntBits(y) & (1 << 31))); + return intBitsToFloat((floatToRawIntBits(x) & ~0x80000000U) ^ (floatToRawIntBits(y) & 0x80000000U)); } static INLINE CONST float signf(float d) { return mulsignf(1, d); } @@ -1920,11 +1920,11 @@ EXPORT CONST float xnextafterf(float x, float y) { cxf = x == 0 ? mulsignf(0, y) : x; memcpy(&cxi, &cxf, sizeof(cxi)); int c = (cxi < 0) == (y < x); - if (c) cxi = -(cxi ^ (1 << 31)); + if (c) cxi = -(cxi ^ 0x80000000U); if (x != y) cxi--; - if (c) cxi = -(cxi ^ (1 << 31)); + if (c) cxi = -(cxi ^ 0x80000000U); memcpy(&cxf, &cxi, sizeof(cxf)); if (cxf == 0 && x != 0) cxf = mulsignf(0, x); From 72008fb19aea41d94dd41b44d8d246e9b6865c95 Mon Sep 17 00:00:00 2001 From: Pierre Blanchard Date: Tue, 15 Oct 2024 15:47:06 +0000 Subject: [PATCH 3/4] Fix errors reported by cppcheck in src/common/addSuffix.c Error: memleakOnRealloc Fix: Free is realloc fails (and at end of main). --- src/common/addSuffix.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/common/addSuffix.c b/src/common/addSuffix.c index cbfaeb19..3543c16f 100644 --- a/src/common/addSuffix.c +++ b/src/common/addSuffix.c @@ -207,7 +207,18 @@ int main(int argc, char **argv) { nkeywords++; if (nkeywords >= nalloc) { nalloc *= 2; - keywords = realloc(keywords, sizeof(char *) * nalloc); + char ** tmp = realloc(keywords, sizeof(char *) * nalloc); + if (tmp == NULL) { + // free keywords if realloc fails + // otherwise address is lost. + free(keywords); + fclose(fp); + fprintf(stderr, "Failed realloc!\n"); + exit(-1); + } + else { + keywords = tmp; + } } } @@ -228,6 +239,8 @@ int main(int argc, char **argv) { fclose(fp); + free(keywords); + exit(0); } From 70c60757d5a6cf45d4df11d7131f5778773c8fe4 Mon Sep 17 00:00:00 2001 From: Pierre Blanchard Date: Tue, 15 Oct 2024 15:51:51 +0000 Subject: [PATCH 4/4] Fix errors reported by cppcheck in src/quad/sleefsimdqp.c Error: va_list 'ap2' was opened but not closed by va_end(). --- src/quad/sleefsimdqp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/quad/sleefsimdqp.c b/src/quad/sleefsimdqp.c index fb295046..182a1421 100644 --- a/src/quad/sleefsimdqp.c +++ b/src/quad/sleefsimdqp.c @@ -3995,6 +3995,8 @@ static int xvprintf(size_t (*consumer)(const char *ptr, size_t size, void *arg), outlen += (*consumer)(xbuf, strlen(xbuf), arg); } + va_end(ap2); + fmt++; }