From fde63699930f9c73b80f6d7f8246a336dbde2355 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 21 Sep 2026 15:48:42 -0500 Subject: [PATCH 1/4] ENH: Declare the three functions that have a published counterpart FslGetHdrImgNames and FslSetIntensityScaling are defined here but declared nowhere, while FslGetIntensityScaling and FslInit are already published. axml_recur_find_xml sits beside axml_recur in afni_xml.h the same way. The upstream fslio was deleted in 2015 in favour of a C++ replacement, so this copy is the surviving one and its header is ours to correct. Additive; no symbol changes. (cherry picked from commit 4673c40690eae3ac1d819dde0ec81723b19edb7d) --- cifti/afni_xml.h | 2 ++ fsliolib/fslio.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/cifti/afni_xml.h b/cifti/afni_xml.h index b48758af..ecc4ab3e 100644 --- a/cifti/afni_xml.h +++ b/cifti/afni_xml.h @@ -88,6 +88,8 @@ int axml_free_xlist(afni_xml_list * axlist); char * axml_attr_value(afni_xml_t * ax, const char * name); int axml_recur(int(*func)(FILE*,afni_xml_t*,int), afni_xml_t * ax); +afni_xml_t * axml_recur_find_xml(int (*func)(afni_xml_t *, int), afni_xml_t * ax, + int depth, int max_depth); /* control API */ diff --git a/fsliolib/fslio.h b/fsliolib/fslio.h index d979fd48..ab1edbd5 100644 --- a/fsliolib/fslio.h +++ b/fsliolib/fslio.h @@ -206,6 +206,8 @@ FSL_API int FslReadRawHeader(void *buffer, const char* filename); /* simple creation and clone/copy operations */ FSL_API FSLIO *FslInit(void); +FSL_API void FslGetHdrImgNames(const char* filename, const FSLIO* fslio, + char** hdrname, char** imgname); FSL_API void FslInitHeader(FSLIO *fslio, short t, size_t x, size_t y, size_t z, size_t v, float vx, float vy, float vz, float tr, @@ -233,6 +235,7 @@ FSL_API void FslGetTimeUnits(FSLIO *fslio, char *units); FSL_API void FslSetDataType(FSLIO *fslio, short t); FSL_API size_t FslGetDataType(FSLIO *fslio, short *t); FSL_API int FslGetIntensityScaling(FSLIO *fslio, float *slope, float *intercept); +FSL_API void FslSetIntensityScaling(FSLIO *fslio, float slope, float intercept); FSL_API void FslSetIntent(FSLIO *fslio, short intent_code, float p1, float p2, float p3); FSL_API short FslGetIntent(FSLIO *fslio, short *intent_code, float *p1, float *p2, float *p3); From 5bfc190386c26181e4cbd150e6931be6d1b52e4e Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 21 Sep 2026 16:00:29 -0500 Subject: [PATCH 2/4] COMP: Give the fsliolib internal functions static linkage Nine functions in fslio.c have external linkage and no declaration in any header. Nothing in the tree calls them across a translation unit, AFNI's vendored copy never calls them, and no public source outside a vendored copy of this file references them, so a caller would have had to declare them itself. Collect their prototypes in one block so the boundary between internal and published is visible in one place. FslSetVoxUnits and FslGetVoxUnits have no caller at all and are left under #if 0 rather than deleted; FslSetTimeUnits and FslGetTimeUnits are published, so the asymmetry is worth keeping visible. Removes nine symbols from libfslio, which the baseline records. (cherry picked from commit 8cdcf1ab1e8bb6aa7f46c66c90bab1c718ea6cbd) --- cmake/exported_symbols_linux.txt | 9 --------- fsliolib/fslio.c | 33 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cmake/exported_symbols_linux.txt b/cmake/exported_symbols_linux.txt index 14effdcd..042959f5 100644 --- a/cmake/exported_symbols_linux.txt +++ b/cmake/exported_symbols_linux.txt @@ -35,7 +35,6 @@ libfslio.so FslCheckForMultipleFileNames libfslio.so FslCloneHeader libfslio.so FslClose libfslio.so FslFileExists -libfslio.so FslFileType libfslio.so FslFileTypeString libfslio.so FslGetAnalyzeOrigin libfslio.so FslGetAuxFile @@ -46,7 +45,6 @@ libfslio.so FslGetDim libfslio.so FslGetDimensionality libfslio.so FslGetEnvOutputType libfslio.so FslGetFileType -libfslio.so FslGetFileType2 libfslio.so FslGetHdrImgNames libfslio.so FslGetIgnoreMFQ libfslio.so FslGetIntensityScaling @@ -54,7 +52,6 @@ libfslio.so FslGetIntent libfslio.so FslGetLeftRightOrder libfslio.so FslGetMMCoord libfslio.so FslGetOverrideOutputType -libfslio.so FslGetReadFileType libfslio.so FslGetRigidXform libfslio.so FslGetStdXform libfslio.so FslGetTimeUnits @@ -62,14 +59,11 @@ libfslio.so FslGetVolSize libfslio.so FslGetVolumeAsScaledDouble libfslio.so FslGetVoxCoord libfslio.so FslGetVoxDim -libfslio.so FslGetVoxUnits libfslio.so FslGetWriteMode libfslio.so FslInit -libfslio.so FslInit4Write libfslio.so FslInitHeader libfslio.so FslIsCompressedFileType libfslio.so FslIsSingleFileType -libfslio.so FslIsValidFileType libfslio.so FslMakeBaseName libfslio.so FslOpen libfslio.so FslReadAllVolumes @@ -96,17 +90,14 @@ libfslio.so FslSetRigidXform libfslio.so FslSetStdXform libfslio.so FslSetTimeUnits libfslio.so FslSetVoxDim -libfslio.so FslSetVoxUnits libfslio.so FslSetWriteMode libfslio.so FslWriteAllVolumes libfslio.so FslWriteHeader libfslio.so FslWriteVolumes libfslio.so FslXOpen -libfslio.so check_for_multiple_filenames libfslio.so convertBufferToScaledDouble libfslio.so d3matrix libfslio.so d4matrix -libfslio.so fsl_fileexists libfslio.so mat44_to_mat33 libnifti2.so disp_nifti_1_header libnifti2.so disp_nifti_2_header diff --git a/fsliolib/fslio.c b/fsliolib/fslio.c index 5b775e77..c49f9a24 100644 --- a/fsliolib/fslio.c +++ b/fsliolib/fslio.c @@ -28,6 +28,18 @@ #include "fslio.h" #include "assert.h" +/* Internal to this file. Nothing in the tree calls them across a + translation unit, no header declares them, and no public source + outside a vendored copy of this file references them. A downstream + project that needs one declares it in fslio.h with FSL_API. */ +static int FslIsValidFileType(int filetype); +static int FslGetFileType2(const FSLIO *fslio, int quiet); +static int FslFileType(const char *fname); +static int FslGetReadFileType(const FSLIO *fslio); +static void FslInit4Write(FSLIO* fslio, const char* filename, int ft); +static int fsl_fileexists(const char* fname); +static int check_for_multiple_filenames(const char* filename); + static int FslIgnoreMFQ=0; static int FslOverrideOutputType=-1; @@ -56,7 +68,7 @@ const char* FslFileTypeString(int filetype) } -int FslIsValidFileType(int filetype) +static int FslIsValidFileType(int filetype) { if ( (filetype!=FSL_TYPE_ANALYZE) && (filetype!=FSL_TYPE_ANALYZE_GZ) && (filetype!=FSL_TYPE_NIFTI) && (filetype!=FSL_TYPE_NIFTI_GZ) && @@ -85,7 +97,7 @@ int FslBaseFileType(int filetype) } -int FslGetFileType2(const FSLIO *fslio, int quiet) +static int FslGetFileType2(const FSLIO *fslio, int quiet) { FSLIO *mutablefslio; if (fslio==NULL) FSLIOERR("FslGetFileType: Null pointer passed for FSLIO"); @@ -190,7 +202,7 @@ int FslGetEnvOutputType(void) } -int FslFileType(const char* fname) +static int FslFileType(const char* fname) { /* return type is FSL_TYPE_* or -1 to indicate undetermined */ /* use name as first priority but if that is ambiguous then resolve using environment */ @@ -224,7 +236,7 @@ int FslFileType(const char* fname) /************************************************************ * FslGetReadFileType ************************************************************/ -/*! \fn int FslGetReadFileType(const FSLIO *fslio) +/*! \fn static int FslGetReadFileType(const FSLIO *fslio) \brief return the best estimate of the true file type This function is used to return the best estimate of the true file type once @@ -389,7 +401,7 @@ void FslSetInit(FSLIO* fslio) -void FslInit4Write(FSLIO* fslio, const char* filename, int ft) +static void FslInit4Write(FSLIO* fslio, const char* filename, int ft) { /* ft determines filetype if ft>=0*/ int imgtype; @@ -502,7 +514,7 @@ void FslCloneHeader(FSLIO *dest, const FSLIO *src) } -int fsl_fileexists(const char* fname) +static int fsl_fileexists(const char* fname) { znzFile fp; fp = znzopen( fname , "rb" , 1 ) ; @@ -559,7 +571,7 @@ int FslCheckForMultipleFileNames(const char* filename) -int check_for_multiple_filenames(const char* filename) +static int check_for_multiple_filenames(const char* filename) { char *basename, *tmpname; char *otype; @@ -1364,7 +1376,9 @@ void FslSetAuxFile(FSLIO *fslio,const char *aux_file) } -void FslSetVoxUnits(FSLIO *fslio, const char *units) +#if 0 +/* No caller in this file, no header declares them, and no public source uses them. */ +static void FslSetVoxUnits(FSLIO *fslio, const char *units) { int unitcode=0; if (fslio==NULL) FSLIOERR("FslSetVoxUnits: Null pointer passed for FSLIO"); @@ -1384,7 +1398,7 @@ void FslSetVoxUnits(FSLIO *fslio, const char *units) } -void FslGetVoxUnits(FSLIO *fslio, char *units) +static void FslGetVoxUnits(FSLIO *fslio, char *units) { if (fslio==NULL) FSLIOERR("FslGetVoxUnits: Null pointer passed for FSLIO"); if (fslio->niftiptr!=NULL) { @@ -1394,6 +1408,7 @@ void FslGetVoxUnits(FSLIO *fslio, char *units) fprintf(stderr,"Warning:: Minc is not yet supported\n"); } } +#endif void FslSetTimeUnits(FSLIO *fslio, const char *units) { From 091233cf40900450977256a49ab0ea06c22840e0 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 21 Sep 2026 16:00:38 -0500 Subject: [PATCH 3/4] COMP: Declare nifti_fileexists where it is defined nifti1_io.c and nifti2_io.c each define nifti_fileexists with external linkage, so libniftiio and libnifti2 export the same name and ELF link order decides which one a caller linking both resolves to. Declaring it locally silences the warning without choosing between publishing it and making it static; that choice needs the duplication settled first, and it covers a hundred names, not this one. (cherry picked from commit 54e74e1ccf30ff3238277cda420805f56e822c7c) --- nifti2/nifti2_io.c | 3 +++ niftilib/nifti1_io.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index c8cc6b23..58b20841 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -472,6 +472,9 @@ static const nifti_type_ele nifti_type_list[] = { }; /*---------------------------------------------------------------------------*/ +/* Defined in both libniftiio and libnifti2; linkage pending that duplication. */ +int nifti_fileexists(const char* fname); + /* prototypes for internal functions - not part of exported library */ /* extension routines */ diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index eb8887f3..1992b188 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -411,6 +411,9 @@ static const nifti_type_ele nifti_type_list[] = { }; /*---------------------------------------------------------------------------*/ +/* Defined in both libniftiio and libnifti2; linkage pending that duplication. */ +int nifti_fileexists(const char* fname); + /* prototypes for internal functions - not part of exported library */ /* extension routines */ From 9fc0c6927a698b2d6382e146826f1285284730a3 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 21 Sep 2026 13:56:40 -0500 Subject: [PATCH 4/4] STYLE: Derive the aux_file bound from sizeof Keeps FslGetAuxFile and FslSetAuxFile deriving the same length so the pair cannot drift if the field width changes. sizeof is 24, so the copy still writes at most 23 bytes. (cherry picked from commit 0c0e66c9537be74d19d67396dd7e4e36dd84e5d7) --- fsliolib/fslio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fsliolib/fslio.c b/fsliolib/fslio.c index c49f9a24..aee7687b 100644 --- a/fsliolib/fslio.c +++ b/fsliolib/fslio.c @@ -1354,8 +1354,9 @@ void FslGetAuxFile(FSLIO *fslio,char *aux_file) { if (fslio==NULL) FSLIOERR("FslGetAuxFile: Null pointer passed for FSLIO"); if (fslio->niftiptr!=NULL) { - strncpy(aux_file,fslio->niftiptr->aux_file, 24); - aux_file[24-1] = '\0'; + /* aux_file must have room for sizeof(nifti_1_header::aux_file) bytes. */ + strncpy(aux_file,fslio->niftiptr->aux_file,sizeof(fslio->niftiptr->aux_file)-1); + aux_file[sizeof(fslio->niftiptr->aux_file)-1] = '\0'; } if (fslio->mincptr!=NULL) { fprintf(stderr,"Warning:: Minc is not yet supported\n");