Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions cifti/afni_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static int show_attrs (afni_xml_control *, const char **, int);

static int64_t loc_strnlen (const char * str, int64_t maxlen);
static afni_xml_t * make_afni_xml (const char * ename, const char ** attr);
static const char * strip_whitespace(const char * str, int slen);
static char * strip_whitespace(const char * str, int slen);

/*----------------------- main I/O functions ---------------------------*/

Expand Down Expand Up @@ -196,22 +196,22 @@ afni_xml_list axml_read_file(const char * fname, int read_data)
{
if( reset_xml_buf(xd, &buf, &bsize) ) break;

blen = fread(buf, 1, bsize, fp);
blen = fread(buf, 1, (size_t)bsize, fp);

/* check for early termination */
bshort = loc_strnlen(buf, blen);
if( bshort < blen ) {
if( xd->verb > 1 )
fprintf(stderr,"-- AXML: truncating fbuffer from %u to %" PRId64 "\n",
blen, bshort);
blen = (int)bshort;
blen = (unsigned)bshort;
}

done = blen < (unsigned) bsize;

if(xd->verb > 4) fprintf(stderr,"-- XML_Parse # %d\n", pcount);
pcount++;
if( XML_Parse(parser, buf, blen, done) == XML_STATUS_ERROR) {
if( XML_Parse(parser, buf, (int)blen, done) == XML_STATUS_ERROR) {
fprintf(stderr,"** %s at line %u\n",
XML_ErrorString(XML_GetErrorCode(parser)),
(unsigned int)XML_GetCurrentLineNumber(parser));
Expand Down Expand Up @@ -284,7 +284,7 @@ afni_xml_list axml_read_buf(const char * buf_in, int64_t bin_len)
/*--- replace fread with buffer copy ---*/

/* decide how much to copy and copy */
if( bin_remain >= bsize ) blen = bsize;
if( bin_remain >= bsize ) blen = (unsigned)bsize;
else blen = bin_remain;

if(blen > 0 && blen <= (unsigned)bsize) {
Expand All @@ -299,7 +299,7 @@ afni_xml_list axml_read_buf(const char * buf_in, int64_t bin_len)

if(xd->verb > 4) fprintf(stderr,"-- XML_Parse # %d\n", pcount);
pcount++;
if( XML_Parse(parser, buf, blen, done) == XML_STATUS_ERROR) {
if( XML_Parse(parser, buf, (int)blen, done) == XML_STATUS_ERROR) {
fprintf(stderr,"** %s at line %u\n",
XML_ErrorString(XML_GetErrorCode(parser)),
(unsigned int)XML_GetCurrentLineNumber(parser));
Expand Down Expand Up @@ -447,8 +447,8 @@ int axml_add_attrs(afni_xml_t * ax, const char ** attr)
return 0;
}

ax->attrs.name = (char **)malloc(natr*sizeof(char *));
ax->attrs.value = (char **)malloc(natr*sizeof(char *));
ax->attrs.name = (char **)malloc((size_t)natr * sizeof(char *));
ax->attrs.value = (char **)malloc((size_t)natr * sizeof(char *));

/* failure? */
if( ! ax->attrs.name || ! ax->attrs.value ) {
Expand Down Expand Up @@ -666,7 +666,7 @@ static int reset_xml_buf(afni_xml_control * xd, char ** buf, int * bsize)
fprintf(stderr,"++ update buf, %d to %d bytes\n",*bsize,xd->buf_size);

*bsize = xd->buf_size;
*buf = (char *)safe_realloc(*buf, (*bsize+1) * sizeof(char));
*buf = (char *)safe_realloc(*buf, (size_t)(*bsize+1) * sizeof(char));
if( ! *buf ) {
fprintf(stderr,"** failed to alloc %d bytes of xml buf!\n", *bsize);
*bsize = 0;
Expand Down Expand Up @@ -826,7 +826,7 @@ static int add_to_xroot_list(afni_xml_control * xd, afni_xml_t * newp)

xd->xroot->len++;
xd->xroot->xlist = (afni_xml_t **)safe_realloc(xd->xroot->xlist,
xd->xroot->len * sizeof(afni_xml_t *));
(size_t)xd->xroot->len * sizeof(afni_xml_t *));
if( ! xd->xroot->xlist ) {
fprintf(stderr,"** failed to alloc %d AXMLT pointers\n", xd->xroot->len);
return 1;
Expand All @@ -844,7 +844,7 @@ static int add_to_xchild_list(afni_xml_t * parent, afni_xml_t * child)

parent->nchild++;
parent->xchild = (afni_xml_t **)safe_realloc(parent->xchild,
parent->nchild * sizeof(afni_xml_t *));
(size_t)parent->nchild * sizeof(afni_xml_t *));
if( ! parent->xchild ) {
fprintf(stderr,"** failed to alloc %d AXML pointers\n", parent->nchild);
return 1;
Expand Down Expand Up @@ -888,7 +888,7 @@ static int show_attrs(afni_xml_control * xd, const char ** attr, int showd)
static void free_whitespace(void) { strip_whitespace(NULL,-2); }

/* if slen == 0, use entire length */
static const char * strip_whitespace(const char * str, int slen)
static char * strip_whitespace(const char * str, int slen)
{
static char * buf = NULL;
static int blen = 0;
Expand All @@ -898,18 +898,18 @@ static const char * strip_whitespace(const char * str, int slen)
if(!str && slen == -2){ free(buf); buf=NULL; blen=0; return 0; }

/* if string is long, forget it */
if( !str || slen > 1024 ) return str;
if( !str || slen > 1024 ) return (char *)str;

len = strlen(str);
if( slen > 0 && slen < len ) len = slen;
if( len <= 0 ) return str;
if( len <= 0 ) return (char *)str;

/* make sure we have local space */
if( len > blen ) { /* allocate a bigger buffer */
buf = (char *)safe_realloc(buf, (len+1) * sizeof(char));
buf = (char *)safe_realloc(buf, (size_t)(len+1) * sizeof(char));
if( !buf ) {
fprintf(stderr,"** failed to alloc wspace buf of len %d\n", len+1);
return str;
return (char *)str;
}
blen = len;
}
Expand All @@ -919,7 +919,7 @@ static const char * strip_whitespace(const char * str, int slen)

if( ifirst == len ) *buf = '\0';
else {
strncpy(buf, str+ifirst, len-ifirst-ilast);
strncpy(buf, str+ifirst, (size_t)(len-ifirst-ilast));
buf[len-ifirst-ilast] = '\0';
}

Expand Down Expand Up @@ -971,14 +971,14 @@ static int append_to_string(char ** ostr, int * olen,

newlen = *olen + ilen;

*ostr = (char *)safe_realloc(*ostr, newlen * sizeof(char));
*ostr = (char *)safe_realloc(*ostr, (size_t)newlen * sizeof(char));
if( !*ostr ) {
fprintf(stderr,"** AX.A2S: failed to alloc %d chars\n", newlen);
return 1;
}

/* copy, starting at old nul char (if any), and terminate */
strncpy((*ostr)+*olen-1, istr, ilen);
strncpy((*ostr)+*olen-1, istr, (size_t)ilen);
(*ostr)[newlen-1] = '\0';
*olen = newlen;

Expand Down
4 changes: 2 additions & 2 deletions cifti/afni_xml_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int axio_num_tokens(const char * str, int64_t maxlen)
if( ! str || ! * str ) return 0;

if( maxlen > 0 ) len = maxlen;
else len = strlen(str);
else len = (int64_t)strlen(str);

ntok = 0;
intok = 0;
Expand Down Expand Up @@ -473,7 +473,7 @@ static int dalloc_as_nifti_type(FILE * fp, afni_xml_t * ax, int64_t nvals,
/* note number of bytes per value and number of values to allocate */
nifti_datatype_sizes(ax->btype, &nbyper, NULL);

ax->bdata = malloc(nbyper * ntok);
ax->bdata = malloc((size_t)(nbyper * ntok));
if( ! ax->bdata ) {
fprintf(fp, "** axio_alloc: failed to allocate %" PRId64 " vals of size %d\n",
ntok, nbyper);
Expand Down
51 changes: 27 additions & 24 deletions fsliolib/fslio.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ void FslWriteAllVolumes(FSLIO *fslio, const void *buffer)

FslGetDim(fslio,&x,&y,&z,&t);
FslWriteHeader(fslio);
FslWriteVolumes(fslio,buffer,t);
FslWriteVolumes(fslio,buffer, (size_t)t);
return;
}

Expand Down Expand Up @@ -931,7 +931,7 @@ size_t FslWriteVolumes(FSLIO *fslio, const void *buffer, size_t nvols)
inbuf = buffer;
tmpbuf = (char *)calloc(nbytes,1);
FslGetDim(fslio,&nx,&ny,&nz,&nv);
nrows = nbytes / (nx * bpv);
nrows = (long int)(nbytes / ((size_t)nx * (size_t)bpv));
for (n=0; n<nrows; n++) {
for (x=0; x<nx; x++) {
for (b=0; b<bpv; b++) {
Expand Down Expand Up @@ -1021,21 +1021,21 @@ size_t FslReadSliceSeries(FSLIO *fslio, void *buffer, short slice, size_t nvols)
slbytes = (size_t)x * (size_t)y * (FslGetDataType(fslio, &type) / 8);
volbytes = slbytes * z;

orig_offset = znztell(fslio->fileptr);
znzseek(fslio->fileptr, slbytes*slice, SEEK_CUR);
orig_offset = (size_t)znztell(fslio->fileptr);
znzseek(fslio->fileptr, (znz_off_t)(slbytes*(size_t)slice), SEEK_CUR);

for (n=0; n<nvols; n++) {
if (n>0) znzseek(fslio->fileptr, volbytes - slbytes, SEEK_CUR);
if (n>0) znzseek(fslio->fileptr, (znz_off_t)(volbytes - slbytes), SEEK_CUR);
if (znzread((char *)buffer+n*slbytes, 1, slbytes, fslio->fileptr) != slbytes)
FSLIOERR("FslReadSliceSeries: failed to read values");
if (fslio->niftiptr->byteorder != nifti_short_order())
nifti_swap_Nbytes(slbytes / fslio->niftiptr->swapsize,
nifti_swap_Nbytes(slbytes / (size_t)fslio->niftiptr->swapsize,
fslio->niftiptr->swapsize, (char *)buffer+n*slbytes);
}


/* restore file pointer to original position */
znzseek(fslio->fileptr,orig_offset,SEEK_SET);
znzseek(fslio->fileptr,(znz_off_t)orig_offset,SEEK_SET);
return n;
}
if (fslio->mincptr!=NULL) {
Expand Down Expand Up @@ -1080,20 +1080,20 @@ size_t FslReadRowSeries(FSLIO *fslio, void *buffer, short row, short slice, size
slbytes = rowbytes * y;
volbytes = slbytes * z;

orig_offset = znztell(fslio->fileptr);
znzseek(fslio->fileptr, rowbytes*row + slbytes*slice, SEEK_CUR);
orig_offset = (size_t)znztell(fslio->fileptr);
znzseek(fslio->fileptr, (znz_off_t)(rowbytes*(size_t)row + slbytes*(size_t)slice), SEEK_CUR);

for (n=0; n<nvols; n++){
if (n>0) znzseek(fslio->fileptr, volbytes - rowbytes, SEEK_CUR);
if (n>0) znzseek(fslio->fileptr, (znz_off_t)(volbytes - rowbytes), SEEK_CUR);
if (znzread((char *)buffer+n*rowbytes, 1, rowbytes, fslio->fileptr) != rowbytes)
FSLIOERR("FslReadRowSeries: failed to read values");
if (fslio->niftiptr->byteorder != nifti_short_order())
nifti_swap_Nbytes(rowbytes / fslio->niftiptr->swapsize,
nifti_swap_Nbytes(rowbytes / (size_t)fslio->niftiptr->swapsize,
fslio->niftiptr->swapsize, (char *)buffer+n*rowbytes);
}

/* restore file pointer to original position */
znzseek(fslio->fileptr,orig_offset,SEEK_SET);
znzseek(fslio->fileptr,(znz_off_t)orig_offset,SEEK_SET);
return n;
}
if (fslio->mincptr!=NULL) {
Expand Down Expand Up @@ -1141,12 +1141,12 @@ size_t FslReadTimeSeries(FSLIO *fslio, void *buffer, short xVox, short yVox, sho
wordsize = fslio->niftiptr->nbyper;
volbytes = (size_t)xdim * (size_t)ydim * (size_t)zdim * wordsize;

orig_offset = znztell(fslio->fileptr);
orig_offset = (size_t)znztell(fslio->fileptr);
offset = ((ydim * zVox + yVox) * xdim + xVox) * wordsize;
znzseek(fslio->fileptr,offset,SEEK_CUR);
znzseek(fslio->fileptr,(znz_off_t)offset,SEEK_CUR);

for (n=0; n<nvols; n++) {
if (n>0) znzseek(fslio->fileptr, volbytes - wordsize, SEEK_CUR);
if (n>0) znzseek(fslio->fileptr, (znz_off_t)(volbytes - wordsize), SEEK_CUR);
if (znzread((char *)buffer+(n*wordsize), 1, wordsize,fslio->fileptr) != wordsize)
FSLIOERR("FslReadTimeSeries: failed to read values");
if (fslio->niftiptr->byteorder != nifti_short_order())
Expand All @@ -1155,7 +1155,7 @@ size_t FslReadTimeSeries(FSLIO *fslio, void *buffer, short xVox, short yVox, sho
}

/* restore file pointer to original position */
znzseek(fslio->fileptr,orig_offset,SEEK_SET);
znzseek(fslio->fileptr,(znz_off_t)orig_offset,SEEK_SET);
return n;

}
Expand Down Expand Up @@ -1225,8 +1225,11 @@ void FslSetDim(FSLIO *fslio, short x, short y, short z, short v)
fslio->niftiptr->dim[6] = fslio->niftiptr->nv;
fslio->niftiptr->dim[7] = fslio->niftiptr->nw;

fslio->niftiptr->nvox = fslio->niftiptr->nx * fslio->niftiptr->ny * fslio->niftiptr->nz
* fslio->niftiptr->nt * fslio->niftiptr->nu * fslio->niftiptr->nv * fslio->niftiptr->nw ;
fslio->niftiptr->nvox =
(size_t)fslio->niftiptr->nx * (size_t)fslio->niftiptr->ny
* (size_t)fslio->niftiptr->nz * (size_t)fslio->niftiptr->nt
* (size_t)fslio->niftiptr->nu * (size_t)fslio->niftiptr->nv
* (size_t)fslio->niftiptr->nw ;

}
if (fslio->mincptr!=NULL) {
Expand Down Expand Up @@ -1267,7 +1270,7 @@ void FslGetDimensionality(FSLIO *fslio, size_t *dim)
{
if (fslio==NULL) FSLIOERR("FslGetDimensionality: Null pointer passed for FSLIO");
if (fslio->niftiptr!=NULL) {
*dim = fslio->niftiptr->ndim;
*dim = (size_t)fslio->niftiptr->ndim;
}
if (fslio->mincptr!=NULL) {
fprintf(stderr,"Warning:: Minc is not yet supported\n");
Expand Down Expand Up @@ -1475,7 +1478,7 @@ size_t FslGetDataType(FSLIO *fslio, short *t)
if (fslio->mincptr!=NULL) {
fprintf(stderr,"Warning:: Minc is not yet supported\n");
}
return (size_t) 8 * nbytepix;
return (size_t) 8 * (size_t)nbytepix;
}


Expand Down Expand Up @@ -2415,20 +2418,20 @@ double ****d4matrix(int th, int zh, int yh, int xh)


/** allocate pointers to vols */
t=(double ****) malloc((size_t)((nvol)*sizeof(double***)));
t=(double ****) malloc((size_t)nvol*sizeof(double***));
if (!t) FSLIOERR("d4matrix: allocation failure");

/** allocate pointers to slices */
t[0]=(double ***) malloc((size_t)((nvol*nslice)*sizeof(double**)));
t[0]=(double ***) malloc((size_t)nvol*(size_t)nslice*sizeof(double**));
if (!t[0]) FSLIOERR("d4matrix: allocation failure");

/** allocate pointers for ydim */
t[0][0]=(double **) malloc((size_t)((nvol*nslice*nrow)*sizeof(double*)));
t[0][0]=(double **) malloc((size_t)nvol*(size_t)nslice*(size_t)nrow*sizeof(double*));
if (!t[0][0]) FSLIOERR("d4matrix: allocation failure");


/** allocate the data blob */
t[0][0][0]=(double *) malloc((size_t)((nvol*nslice*nrow*ncol)*sizeof(double)));
t[0][0][0]=(double *) malloc((size_t)nvol*(size_t)nslice*(size_t)nrow*(size_t)ncol*sizeof(double));
if (!t[0][0][0]) FSLIOERR("d4matrix: allocation failure");


Expand Down
Loading
Loading