From a492d3c34102a4dbd7beca36d8a3d80a5a11a215 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 14 Jan 2026 17:19:28 -0500 Subject: [PATCH 1/2] BUG: Check the allocation in nifti_intent_code before copying into it cppcheck 2.19 nullPointerOutOfMemory: the uppercase copy of the name was written into an unchecked malloc result. Return -1, the same value the function already uses for an unrecognized name. (cherry picked from commit c2d181ed5a1fef5d44f7995afce1f07e3223741c) --- nifticdf/nifticdf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nifticdf/nifticdf.c b/nifticdf/nifticdf.c index bdab933f..bf00c52a 100644 --- a/nifticdf/nifticdf.c +++ b/nifticdf/nifticdf.c @@ -11050,6 +11050,8 @@ int nifti_intent_code( const char *name ) if( name == NULL || *name == '\0' ) return -1 ; unam = (char *)malloc(strlen(name)+1); + if (!unam) + return -1 ; strcpy(unam,name); for( upt=unam ; *upt != '\0' ; upt++ ) *upt = (char)toupper(*upt) ; From e7f8ed82c43b5e1bf08a09442c5bdbd1eadc0200 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 14 Jan 2026 17:19:28 -0500 Subject: [PATCH 2/2] STYLE: Drop the unreachable returns after FSLIOERR cppcheck 2.19 unreachableCode: FSLIOERR ends in exit(EXIT_FAILURE), so the return statements following it in FslReadAllVolumes and FslReadHeader can never run. (cherry picked from commit f5f3766d60cdfa9cb794f752563a3de8625a40aa) --- fsliolib/fslio.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fsliolib/fslio.c b/fsliolib/fslio.c index 5b775e77..0a7ea62f 100644 --- a/fsliolib/fslio.c +++ b/fsliolib/fslio.c @@ -809,7 +809,6 @@ void* FslReadAllVolumes(FSLIO* fslio, char* filename) /* check for failure, from David Akers */ if (fslio->niftiptr == NULL) { FSLIOERR("FslReadAllVolumes: error reading NIfTI image"); - return(NULL); } FslSetFileType(fslio,fslio->niftiptr->nifti_type); @@ -2092,7 +2091,6 @@ FSLIO * FslReadHeader(char *fname) if (fslio->niftiptr == NULL) { FSLIOERR("FslReadHeader: error reading header information"); - return(NULL); } fslio->file_mode = FslGetReadFileType(fslio);