From 14f072acca1d44d4c08a2ff167feaab2ed189409 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Tue, 22 Sep 2026 15:42:33 -0500 Subject: [PATCH] BUG: Give the orientation switches a defined default nifti_mat44_to_orientation() and its two siblings assign i, j and k from three switches on ibest*pbest, jbest*qbest and kbest*rbest. The default arm fell through without assigning, leaving the variable holding the loop counter that last wrote it, which is not an orientation code. Assigning 0 there gives the fall-through a value outside the valid range 1..6 and says so at the point it happens, rather than initialising at the declaration where the reason is no longer visible. Under -Wconditional-uninitialized the tree goes from 11 warnings to 4, and the four that remain are an unrelated variable. Co-Authored-By: Sean McBride (cherry picked from commit 7b88e9a4722ec13bb78c5429be05c187a0f497a1) --- nifti2/nifti2_io.c | 12 ++++++------ niftilib/nifti1_io.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index c8cc6b23..acdbc089 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -2778,7 +2778,7 @@ void nifti_dmat44_to_orientation( nifti_dmat44 R , case -2: i = NIFTI_A2P ; break ; case 3: i = NIFTI_I2S ; break ; case -3: i = NIFTI_S2I ; break ; - default: assert(0) ; break ; + default: assert(0) ; i = 0 ; break ; } switch( jbest*qbest ){ @@ -2788,7 +2788,7 @@ void nifti_dmat44_to_orientation( nifti_dmat44 R , case -2: j = NIFTI_A2P ; break ; case 3: j = NIFTI_I2S ; break ; case -3: j = NIFTI_S2I ; break ; - default: assert(0) ; break ; + default: assert(0) ; j = 0 ; break ; } switch( kbest*rbest ){ @@ -2798,7 +2798,7 @@ void nifti_dmat44_to_orientation( nifti_dmat44 R , case -2: k = NIFTI_A2P ; break ; case 3: k = NIFTI_I2S ; break ; case -3: k = NIFTI_S2I ; break ; - default: assert(0) ; break ; + default: assert(0) ; k = 0 ; break ; } *icod = i ; *jcod = j ; *kcod = k ; } @@ -2961,7 +2961,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) case -2: i = NIFTI_A2P ; break ; case 3: i = NIFTI_I2S ; break ; case -3: i = NIFTI_S2I ; break ; - default: break; + default: i = 0 ; break; } switch( jbest*qbest ){ @@ -2971,7 +2971,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) case -2: j = NIFTI_A2P ; break ; case 3: j = NIFTI_I2S ; break ; case -3: j = NIFTI_S2I ; break ; - default: break; + default: j = 0 ; break; } switch( kbest*rbest ){ @@ -2981,7 +2981,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) case -2: k = NIFTI_A2P ; break ; case 3: k = NIFTI_I2S ; break ; case -3: k = NIFTI_S2I ; break ; - default: break; + default: k = 0 ; break; } *icod = i ; *jcod = j ; *kcod = k ; } diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index eb8887f3..ad2552bd 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -2109,7 +2109,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) case -2: i = NIFTI_A2P ; break ; case 3: i = NIFTI_I2S ; break ; case -3: i = NIFTI_S2I ; break ; - default: assert(0) ; break ; + default: assert(0) ; i = 0 ; break ; } switch( jbest*qbest ){ @@ -2119,7 +2119,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) case -2: j = NIFTI_A2P ; break ; case 3: j = NIFTI_I2S ; break ; case -3: j = NIFTI_S2I ; break ; - default: assert(0) ; break ; + default: assert(0) ; j = 0 ; break ; } switch( kbest*rbest ){ @@ -2129,7 +2129,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) case -2: k = NIFTI_A2P ; break ; case 3: k = NIFTI_I2S ; break ; case -3: k = NIFTI_S2I ; break ; - default: assert(0) ; break ; + default: assert(0) ; k = 0 ; break ; } *icod = i ; *jcod = j ; *kcod = k ;