From f20f346769e7887a2b7d0f5dc1fea2567c9e6edb Mon Sep 17 00:00:00 2001 From: Jian Guan Date: Mon, 25 Jan 2021 16:27:58 -0800 Subject: [PATCH 1/2] clean MSAN warnings 1. Changed to "calloc" to create and initialize array. 2. Initialized `info` before being passed into blas package. --- src/matrices/blasglue.c | 16 ++++++++-------- src/util/check.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/matrices/blasglue.c b/src/matrices/blasglue.c index d03301f1..7a41e5e9 100644 --- a/src/matrices/blasglue.c +++ b/src/matrices/blasglue.c @@ -247,7 +247,7 @@ void blasglue_herk(char uplo, char trans, int n, int k, int lapackglue_potrf(char uplo, int n, scalar *A, int fdA) { - int info; + int info = 0; uplo = uplo == 'U' ? 'L' : 'U'; @@ -259,7 +259,7 @@ int lapackglue_potrf(char uplo, int n, scalar *A, int fdA) int lapackglue_potri(char uplo, int n, scalar *A, int fdA) { - int info; + int info = 0; uplo = uplo == 'U' ? 'L' : 'U'; @@ -272,7 +272,7 @@ int lapackglue_potri(char uplo, int n, scalar *A, int fdA) int lapackglue_hetrf(char uplo, int n, scalar *A, int fdA, int *ipiv, scalar *work, int lwork) { - int info; + int info = 0; uplo = uplo == 'U' ? 'L' : 'U'; @@ -289,7 +289,7 @@ int lapackglue_hetrf(char uplo, int n, scalar *A, int fdA, int lapackglue_hetri(char uplo, int n, scalar *A, int fdA, int *ipiv, scalar *work) { - int info; + int info = 0; uplo = uplo == 'U' ? 'L' : 'U'; @@ -306,7 +306,7 @@ int lapackglue_hetri(char uplo, int n, scalar *A, int fdA, void lapackglue_heev(char jobz, char uplo, int n, scalar *A, int fdA, real *w, scalar *work, int lwork, real *rwork) { - int info; + int info = 0; uplo = uplo == 'U' ? 'L' : 'U'; @@ -326,7 +326,7 @@ void lapackglue_geev(char jobvl, char jobvr, int n, scalar *VL, int fdVL, scalar *VR, int fdVR, scalar *work, int lwork, real *rwork) { - int info; + int info = 0; #ifdef SCALAR_COMPLEX F(geev,GEEV) (&jobvl, &jobvr, &n, A, &fdA, w, VL, &fdVL, VR, &fdVR, @@ -351,7 +351,7 @@ void lapackglue_hegv(int itype, char jobz, char uplo, int n, scalar *A, int fdA, scalar *B, int fdB, real *w, scalar *work, int lwork, real *rwork) { - int info; + int info = 0; uplo = uplo == 'U' ? 'L' : 'U'; @@ -369,7 +369,7 @@ void lapackglue_hegv(int itype, char jobz, char uplo, int n, void lapackglue_syev(char jobz, char uplo, int n, real *A, int fdA, real *w, real *work, int lwork) { - int info; + int info = 0; uplo = uplo == 'U' ? 'L' : 'U'; diff --git a/src/util/check.h b/src/util/check.h index 6cf4d29f..288cdc15 100644 --- a/src/util/check.h +++ b/src/util/check.h @@ -59,7 +59,7 @@ extern void debug_check_memory_leaks(void); #define CHK_MALLOC(p, t, n) { \ size_t CHK_MALLOC_n_tmp = (n); \ - (p) = (t *) malloc(sizeof(t) * CHK_MALLOC_n_tmp); \ + (p) = (t *) calloc(CHK_MALLOC_n_tmp, sizeof(t)); \ CHECK((p) || CHK_MALLOC_n_tmp == 0, "out of memory!"); \ } From 65fd7ee70d44683bda63a7cacb4a421c75cf5a5e Mon Sep 17 00:00:00 2001 From: Jian Guan Date: Wed, 10 Feb 2021 18:45:07 -0800 Subject: [PATCH 2/2] Use memset to avoid a warning from MSan To avoid the warning of use-of-uninitialized-value from MSan and minimize the change to the original code, we changed`calloc` back to `malloc`, and initilize an array using `memset` at the place MSan complains. --- src/matrices/sqmatrix.c | 2 ++ src/util/check.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/matrices/sqmatrix.c b/src/matrices/sqmatrix.c index 49b9531c..3542dfb9 100644 --- a/src/matrices/sqmatrix.c +++ b/src/matrices/sqmatrix.c @@ -24,6 +24,7 @@ #include "matrices.h" #include "blasglue.h" +#include /* Simple operations on sqmatrices. Also, some not-so-simple operations, like inversion and eigenvalue decomposition. */ @@ -323,6 +324,7 @@ void sqmatrix_sqrt(sqmatrix Usqrt, sqmatrix U, sqmatrix W) CHECK(Usqrt.p == U.p && U.p == W.p, "matrices not conformant"); CHK_MALLOC(eigenvals, real, U.p); + memset(eigenvals, 0, sizeof(real) * U.p); sqmatrix_eigensolve(U, eigenvals, W); diff --git a/src/util/check.h b/src/util/check.h index 288cdc15..6cf4d29f 100644 --- a/src/util/check.h +++ b/src/util/check.h @@ -59,7 +59,7 @@ extern void debug_check_memory_leaks(void); #define CHK_MALLOC(p, t, n) { \ size_t CHK_MALLOC_n_tmp = (n); \ - (p) = (t *) calloc(CHK_MALLOC_n_tmp, sizeof(t)); \ + (p) = (t *) malloc(sizeof(t) * CHK_MALLOC_n_tmp); \ CHECK((p) || CHK_MALLOC_n_tmp == 0, "out of memory!"); \ }