From ab9772fe6f2a4f7cb344e26bc700cb724490e673 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Fri, 14 Aug 2026 23:21:59 -0400 Subject: [PATCH] ENH: Zero-initialize the matrix locals clang cannot prove are filled Eight of the eleven -Wconditional-uninitialized warnings are false positives of one shape: a mat33, mat44 or nifti_dmat44 local filled by a nested loop over all of its elements, which clang cannot prove covers the whole object. There is no defect in any of the eight, but the warning earns its place -- another instance of the same diagnostic is a real defect in nifti_mat44_to_orientation(), where j and k can genuinely be read unset -- so the matrices get an explicit zero initializer rather than the check being switched off. The cost is zeroing 36 to 128 bytes in matrix helpers that are not on any hot path. nifti_mat44_to_orientation() is left for the change that fixes it; this commit clears the false positives around it. --- fsliolib/fslio.c | 2 +- nifti2/nifti2_io.c | 8 ++++---- niftilib/nifti1_io.c | 2 +- niftilib/nifti_tester001.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fsliolib/fslio.c b/fsliolib/fslio.c index 44053fcf..75d2bfde 100644 --- a/fsliolib/fslio.c +++ b/fsliolib/fslio.c @@ -1756,7 +1756,7 @@ int FslGetIntensityScaling(FSLIO *fslio, float *slope, float *intercept) mat33 mat44_to_mat33(mat44 x) { - mat33 y; + mat33 y = { { { 0.0f } } }; int i,j; for (i=0; i<3; i++) { for (j=0; j<3; j++) { diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index 70c136e8..3fd44dd7 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -2451,7 +2451,7 @@ float nifti_mat33_colnorm( mat33 A ) /* max column norm of 3x3 matrix */ nifti_dmat33 nifti_dmat33_mul( nifti_dmat33 A , nifti_dmat33 B ) /* multiply 2 3x3 matrices */ { - nifti_dmat33 C ; int i,j ; + nifti_dmat33 C = { { { 0.0 } } } ; int i,j ; for( i=0 ; i < 3 ; i++ ) for( j=0 ; j < 3 ; j++ ) C.m[i][j] = A.m[i][0] * B.m[0][j] @@ -2465,7 +2465,7 @@ nifti_dmat33 nifti_dmat33_mul( nifti_dmat33 A , nifti_dmat33 B ) *//*--------------------------------------------------------------------*/ mat33 nifti_mat33_mul( mat33 A , mat33 B ) /* multiply 2 3x3 matrices */ { - mat33 C ; int i,j ; + mat33 C = { { { 0.0f } } } ; int i,j ; for( i=0 ; i < 3 ; i++ ) for( j=0 ; j < 3 ; j++ ) C.m[i][j] = A.m[i][0] * B.m[0][j] @@ -2479,7 +2479,7 @@ mat33 nifti_mat33_mul( mat33 A , mat33 B ) /* multiply 2 3x3 matrices */ *//*--------------------------------------------------------------------*/ nifti_dmat44 nifti_dmat44_mul( nifti_dmat44 A , nifti_dmat44 B ) { - nifti_dmat44 C ; int i,j,k ; + nifti_dmat44 C = { { { 0.0 } } } ; int i,j,k ; for( i=0 ; i < 4 ; i++ ) for( j=0 ; j < 4 ; j++ ) { C.m[i][j] = 0.0; @@ -2494,7 +2494,7 @@ nifti_dmat44 nifti_dmat44_mul( nifti_dmat44 A , nifti_dmat44 B ) *//*--------------------------------------------------------------------*/ mat44 nifti_mat44_mul( mat44 A , mat44 B ) { - mat44 C ; int i,j,k ; + mat44 C = { { { 0.0f } } } ; int i,j,k ; for( i=0 ; i < 4 ; i++ ) for( j=0 ; j < 4 ; j++ ) { C.m[i][j] = 0.0; diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index c9142554..bbbb236c 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -1887,7 +1887,7 @@ float nifti_mat33_colnorm( mat33 A ) /* max column norm of 3x3 matrix */ *//*--------------------------------------------------------------------*/ mat33 nifti_mat33_mul( mat33 A , mat33 B ) /* multiply 2 3x3 matrices */ { - mat33 C ; int i,j ; + mat33 C = { { { 0.0f } } } ; int i,j ; for( i=0 ; i < 3 ; i++ ) for( j=0 ; j < 3 ; j++ ) C.m[i][j] = A.m[i][0] * B.m[0][j] diff --git a/niftilib/nifti_tester001.c b/niftilib/nifti_tester001.c index 126e6bd6..b44ba9f2 100644 --- a/niftilib/nifti_tester001.c +++ b/niftilib/nifti_tester001.c @@ -636,7 +636,7 @@ int main (int argc, const char *argv[]) nifti_datatype_sizes_test(DT_COMPLEX256,32,16); { - mat44 R; + mat44 R = { { { 0.0f } } }; unsigned i,j; for(i = 0; i < 4; i++) for(j = 0; j < 4; j++)