diff --git a/cifti/afni_xml.c b/cifti/afni_xml.c index 35a7f64a..5a92738a 100644 --- a/cifti/afni_xml.c +++ b/cifti/afni_xml.c @@ -196,7 +196,7 @@ afni_xml_list axml_read_file(const char * fname, int read_data) { if( reset_xml_buf(xd, &buf, &bsize) ) break; - blen = fread(buf, 1, (size_t)bsize, fp); + blen = (unsigned)fread(buf, 1, (size_t)bsize, fp); /* check for early termination */ bshort = loc_strnlen(buf, blen); @@ -285,7 +285,7 @@ afni_xml_list axml_read_buf(const char * buf_in, int64_t bin_len) /* decide how much to copy and copy */ if( bin_remain >= bsize ) blen = (unsigned)bsize; - else blen = bin_remain; + else blen = (unsigned)bin_remain; if(blen > 0 && blen <= (unsigned)bsize) { memcpy(buf, bin_ptr, blen); @@ -900,7 +900,7 @@ static char * strip_whitespace(const char * str, int slen) /* if string is long, forget it */ if( !str || slen > 1024 ) return (char *)str; - len = strlen(str); + len = (int)strlen(str); if( slen > 0 && slen < len ) len = slen; if( len <= 0 ) return (char *)str; @@ -994,7 +994,7 @@ static int disp_gen_text(afni_xml_control * xd, const char * header, if( len == wlen ) { str = "whitespace"; /* just note the whitespace */ - len = strlen(str); + len = (int)strlen(str); } show_depth(xd, 1); diff --git a/cifti/afni_xml_io.c b/cifti/afni_xml_io.c index ce60483b..bcd7d4da 100644 --- a/cifti/afni_xml_io.c +++ b/cifti/afni_xml_io.c @@ -136,7 +136,7 @@ int axio_num_tokens(const char * str, int64_t maxlen) } } - return ntok; + return (int)ntok; } @@ -165,7 +165,7 @@ int axio_show_attrs(FILE * fp, afni_xml_t * ax, int indent) if( !ax ) return 1; for( ind = 0, maxl = 1; ind < ax->attrs.length; ind++ ) { - slen = strlen(ax->attrs.name[ind]); + slen = (int)strlen(ax->attrs.name[ind]); if( slen > maxl ) maxl = slen; } diff --git a/fsliolib/fslio.c b/fsliolib/fslio.c index 44053fcf..77b8f055 100644 --- a/fsliolib/fslio.c +++ b/fsliolib/fslio.c @@ -207,7 +207,7 @@ static int FslFileType(const char* fname) int flen; int retval=-1; if (fname==NULL) return retval; - flen = strlen(fname); + flen = (int)strlen(fname); /* debian@onerussian.com had to group conditions to avoid possible * illegal memory read-ins */ if (flen<5) return retval; /* smallest name + extension is a.nii */ @@ -301,7 +301,7 @@ char *FslMakeBaseName(const char *fname) char *basename; int blen; basename = nifti_makebasename(fname); - blen = strlen(basename); + blen = (int)strlen(basename); #ifdef HAVE_ZLIB if ((blen>7) && (strcmp(basename + blen-7,".mnc.gz") == 0)) { basename[blen-7]='\0'; return basename; } @@ -841,13 +841,13 @@ void* FslReadAllVolumes(FSLIO* fslio, char* filename) */ size_t FslReadVolumes(FSLIO *fslio, void *buffer, size_t nvols) { - int volbytes; + size_t volbytes; size_t retval=0; if (fslio==NULL) FSLIOERR("FslReadVolumes: Null pointer passed for FSLIO"); if (znz_isnull(fslio->fileptr)) FSLIOERR("FslReadVolumes: Null file pointer"); if (fslio->niftiptr!=NULL) { fslio->niftiptr->data = buffer; - volbytes = FslGetVolSize(fslio) * fslio->niftiptr->nbyper; + volbytes = FslGetVolSize(fslio) * (size_t)fslio->niftiptr->nbyper; retval = nifti_read_buffer(fslio->fileptr,fslio->niftiptr->data,nvols*volbytes,fslio->niftiptr); retval /= volbytes; } @@ -1167,13 +1167,14 @@ size_t FslReadTimeSeries(FSLIO *fslio, void *buffer, short xVox, short yVox, sho int FslSeekVolume(FSLIO *fslio, size_t vols) { - int offset; + znz_off_t offset; if (fslio==NULL) FSLIOERR("FslSeekVolume: Null pointer passed for FSLIO"); if (fslio->niftiptr!=NULL) { - offset = fslio->niftiptr->iname_offset + - vols * FslGetVolSize(fslio) * fslio->niftiptr->nbyper; + offset = (znz_off_t)fslio->niftiptr->iname_offset + + (znz_off_t)vols * (znz_off_t)FslGetVolSize(fslio) * fslio->niftiptr->nbyper; if (znz_isnull(fslio->fileptr)) FSLIOERR("FslSeekVolume: Null file pointer"); - return znzseek(fslio->fileptr,offset,SEEK_SET); + /* The int return cannot represent an offset beyond 2GB. */ + return (int)znzseek(fslio->fileptr,offset,SEEK_SET); } if (fslio->mincptr!=NULL) { fprintf(stderr,"Warning:: Minc is not yet supported\n"); @@ -1257,8 +1258,8 @@ void FslSetDimensionality(FSLIO *fslio, size_t dim) { if (fslio==NULL) FSLIOERR("FslSetDimensionality: Null pointer passed for FSLIO"); if (fslio->niftiptr!=NULL) { - fslio->niftiptr->ndim = dim; - fslio->niftiptr->dim[0] = dim; + fslio->niftiptr->ndim = (int)dim; + fslio->niftiptr->dim[0] = (int)dim; } if (fslio->mincptr!=NULL) { fprintf(stderr,"Warning:: Minc is not yet supported\n"); @@ -2044,7 +2045,7 @@ int FslReadRawHeader(void *buffer, const char* filename) fprintf(stderr,"Could not open header %s\n",filename); return 0; } - retval = znzread(buffer,1,348,fp); + retval = (int)znzread(buffer,1,348,fp); znzclose(fp); if (retval != 348) { fprintf(stderr,"Could not read header %s\n",filename); @@ -2148,9 +2149,9 @@ double ***FslGetVolumeAsScaledDouble(FSLIO *fslio, int vol) if ((fslio->niftiptr->dim[0] < 3) || (fslio->niftiptr->dim[0] > 4)) FSLIOERR("FslGetVolumeAsScaledDouble: Incorrect dataset dimension, 3D-4D needed"); - xx = (fslio->niftiptr->nx == 0 ? 1 : (long)fslio->niftiptr->nx); - yy = (fslio->niftiptr->ny == 0 ? 1 : (long)fslio->niftiptr->ny); - zz = (fslio->niftiptr->nz == 0 ? 1 : (long)fslio->niftiptr->nz); + xx = (fslio->niftiptr->nx == 0 ? 1 : fslio->niftiptr->nx); + yy = (fslio->niftiptr->ny == 0 ? 1 : fslio->niftiptr->ny); + zz = (fslio->niftiptr->nz == 0 ? 1 : fslio->niftiptr->nz); if (fslio->niftiptr->scl_slope == 0) { slope = 1.0; @@ -2232,10 +2233,10 @@ double ****FslGetBufferAsScaledDouble(FSLIO *fslio) if ((fslio->niftiptr->dim[0] <= 0) || (fslio->niftiptr->dim[0] > 4)) FSLIOERR("FslGetBufferAsScaledDouble: Incorrect dataset dimension, 1-4D needed"); - xx = (fslio->niftiptr->nx == 0 ? 1 : (long)fslio->niftiptr->nx); - yy = (fslio->niftiptr->ny == 0 ? 1 : (long)fslio->niftiptr->ny); - zz = (fslio->niftiptr->nz == 0 ? 1 : (long)fslio->niftiptr->nz); - tt = (fslio->niftiptr->nt == 0 ? 1 : (long)fslio->niftiptr->nt); + xx = (fslio->niftiptr->nx == 0 ? 1 : fslio->niftiptr->nx); + yy = (fslio->niftiptr->ny == 0 ? 1 : fslio->niftiptr->ny); + zz = (fslio->niftiptr->nz == 0 ? 1 : fslio->niftiptr->nz); + tt = (fslio->niftiptr->nt == 0 ? 1 : fslio->niftiptr->nt); if (fslio->niftiptr->scl_slope == 0) { slope = 1.0; diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index 70c136e8..c6232fd2 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -478,9 +478,9 @@ int nifti_fileexists(const char* fname); /* prototypes for internal functions - not part of exported library */ /* extension routines */ -static int nifti_read_extensions(nifti_image *nim, znzFile fp, int64_t remain); -static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, int remain, znzFile fp ); -static int nifti_check_extension(nifti_image *nim, int size,int code, int rem); +static int64_t nifti_read_extensions(nifti_image *nim, znzFile fp, int64_t remain); +static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, int64_t remain, znzFile fp ); +static int nifti_check_extension(nifti_image *nim, int size,int code, int64_t rem); static void update_nifti_image_for_brick_list(nifti_image * nim, int64_t nbricks); static int nifti_add_exten_to_list(nifti1_extension * new_ext, @@ -503,7 +503,7 @@ static int nifti_NBL_matches_nim(const nifti_image *nim, static int rci_read_data(nifti_image *nim, int64_t *pivots, int64_t *prods, int nprods, const int64_t dims[], char *data, znzFile fp, int64_t base_offset); -static int rci_alloc_mem(void **data, const int64_t prods[8], int nprods, int nbyper); +static int64_t rci_alloc_mem(void **data, const int64_t prods[8], int nprods, int nbyper); static int make_pivot_list(nifti_image * nim, const int64_t dims[8], int64_t pivots[8], int64_t prods[8], int * nprods ); @@ -886,7 +886,8 @@ int nifti_image_load_bricks( nifti_image * nim , int64_t nbricks, znzclose(fp); - return NBL->nbricks; + /* the count came from the caller, who passed it as this many bricks */ + return (int)NBL->nbricks; } @@ -5983,7 +5984,7 @@ nifti_image *nifti_image_read( const char *hname , int read_data ) return NULL; } else if ( rv == 1 ) { /* process special file type */ - nim = nifti_read_ascii_image( fp, hfile, filesize, read_data ); + nim = nifti_read_ascii_image( fp, hfile, (int)filesize, read_data ); znzclose(fp); free(hfile); return nim; @@ -6251,7 +6252,7 @@ nifti_image * nifti_read_ascii_image(znzFile fp, const char *fname, int flen, * * return the number of extensions read in, or < 0 on error *----------------------------------------------------------------------*/ -static int nifti_read_extensions( nifti_image *nim, znzFile fp, int64_t remain ) +static int64_t nifti_read_extensions( nifti_image *nim, znzFile fp, int64_t remain ) { nifti1_extender extdr; /* defines extension existence */ nifti1_extension extn; /* single extension to process */ @@ -6479,7 +6480,7 @@ static int nifti_fill_extension( nifti1_extension *ext, const char * data, * error : -1 *----------------------------------------------------------------------*/ static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, - int remain, znzFile fp ) + int64_t remain, znzFile fp ) { int swap = nim->byteorder != nifti_short_order(); int count, size, code = -1; @@ -6490,7 +6491,7 @@ static int nifti_read_next_extension( nifti1_extension * nex, nifti_image *nim, if( remain < 16 ){ if( g_opts.debug > 2 ) - fprintf(stderr,"-d only %d bytes remain, so no extension\n", remain); + fprintf(stderr,"-d only %" PRId64 " bytes remain, so no extension\n", remain); return 0; } @@ -6696,7 +6697,7 @@ int nifti_is_valid_ecode( int ecode ) /*---------------------------------------------------------------------- * check for valid size and code, as well as can be done *----------------------------------------------------------------------*/ -static int nifti_check_extension(nifti_image *nim, int size, int code, int rem) +static int nifti_check_extension(nifti_image *nim, int size, int code, int64_t rem) { /* check for bad code before bad size */ if( ! nifti_is_valid_ecode(code) ) { @@ -6713,7 +6714,7 @@ static int nifti_check_extension(nifti_image *nim, int size, int code, int rem) if( size > rem ){ if( g_opts.debug > 2 ) - fprintf(stderr,"-d ext size %d, space %d, no extension\n", size, rem); + fprintf(stderr,"-d ext size %d, space %" PRId64 ", no extension\n", size, rem); return 0; } @@ -9525,7 +9526,7 @@ static int rci_read_data(nifti_image * nim, int64_t * pivots, int64_t * prods, return total size on success, and < 0 on failure */ -static int rci_alloc_mem(void **data, const int64_t prods[8], int nprods, int nbyper ) +static int64_t rci_alloc_mem(void **data, const int64_t prods[8], int nprods, int nbyper ) { int64_t size; int memindex; diff --git a/nifti2/nifti_tool.c b/nifti2/nifti_tool.c index fdde86f6..f92cf9da 100644 --- a/nifti2/nifti_tool.c +++ b/nifti2/nifti_tool.c @@ -6771,7 +6771,7 @@ int act_disp_ci( nt_opts * opts ) } /* should we change disp_raw_data to allow for 64-bit nvalues? */ - disp_raw_data(data, nim->datatype, len64 / nim->nbyper, space, 1); + disp_raw_data(data, nim->datatype, (int)(len64 / nim->nbyper), space, 1); nifti_image_free(nim); } @@ -7575,7 +7575,7 @@ void * nt_read_header(const char * fname, int * nver, int * swapped, int check, * * the returned object is a (max 4-D) nifti_image *----------------------------------------------------------------------*/ -nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int len, +nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int64_t len, int64_t * list, nifti_brick_list * NBL) { nifti_image * nim; @@ -7621,8 +7621,8 @@ nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int len, disp_raw_data(opts->new_dim, DT_INT64, 8, ' ', 1); printf(" new_datatype = %d\n", opts->new_datatype); if( list && len > 0 ) { - printf(" brick_list[%d] = ", len); - disp_raw_data(list, DT_INT64, len, ' ', 1); + printf(" brick_list[%" PRId64 "] = ", len); + disp_raw_data(list, DT_INT64, (int)len, ' ', 1); } fflush(stdout); /* disp_raw_data uses stdout */ } diff --git a/nifti2/nifti_tool.h b/nifti2/nifti_tool.h index ba57369d..f32e1312 100644 --- a/nifti2/nifti_tool.h +++ b/nifti2/nifti_tool.h @@ -320,7 +320,7 @@ NI2_API int write_hdr2_to_file(nifti_2_header * nhdr, const char * fname); /* wrappers for nifti reading functions (allow MAKE_IM) */ NI2_API nifti_image * nt_image_read (nt_opts * opts, const char * fname, int read_data, int make_ver); -NI2_API nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int len, +NI2_API nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int64_t len, int64_t * list, nifti_brick_list * NBL); NI2_API void * nt_read_header(const char * fname, int * nver, int * swapped, int check, int new_datatype, int64_t new_dim[8]); diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index c9142554..1d374f63 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -7096,7 +7096,9 @@ int nifti_read_collapsed_image( nifti_image * nim, const int dims [8], fprintf(stderr,"+d read %d bytes of collapsed image from %s\n", bytes, nim->fname); - return bytes; + /* nifti_read_subregion_image() is declared to return int; a subregion + larger than 2GB cannot be requested through its int region_size. */ + return (int)bytes; } @@ -7320,7 +7322,9 @@ int nifti_read_subregion_image( nifti_image * nim, } } znzclose(fp); - return bytes; + /* nifti_read_subregion_image() is declared to return int; a subregion + larger than 2GB cannot be requested through its int region_size. */ + return (int)bytes; }