From: <kin...@us...> - 2012-10-03 19:05:38
|
Revision: 5704 http://teem.svn.sourceforge.net/teem/?rev=5704&view=rev Author: kindlmann Date: 2012-10-03 19:05:29 +0000 (Wed, 03 Oct 2012) Log Message: ----------- rethinking storage of backwards - must fit in (signed) long because byteSkip fit in the same type, but ultimately have to rethink cast of size_t bsize to long Modified Paths: -------------- teem/trunk/src/nrrd/encodingGzip.c teem/trunk/src/nrrd/read.c Modified: teem/trunk/src/nrrd/encodingGzip.c =================================================================== --- teem/trunk/src/nrrd/encodingGzip.c 2012-10-03 18:36:38 UTC (rev 5703) +++ teem/trunk/src/nrrd/encodingGzip.c 2012-10-03 19:05:29 UTC (rev 5704) @@ -75,7 +75,7 @@ of memory from "buff" into the given "_data" pointer */ char *buff; airArray *buffArr; - unsigned long backwards; + long backwards; /* setting the airArray increment to twice the chunk size means that for headers that are small compared to the data, the airArray never @@ -119,16 +119,16 @@ return 1; } /* backwards is (positive) number of bytes AFTER data that we ignore */ - backwards = AIR_CAST(unsigned long, -nio->byteSkip - 1); - if (sizeRed < sizeData + backwards) { + backwards = -nio->byteSkip - 1; + if (sizeRed < sizeData + AIR_CAST(size_t, backwards)) { char stmp1[AIR_STRLEN_SMALL], stmp2[AIR_STRLEN_SMALL]; biffAddf(NRRD, "%s: expected %s bytes but received only %s", me, - airSprintSize_t(stmp1, sizeData + backwards), + airSprintSize_t(stmp1, sizeData + AIR_CAST(size_t, backwards)), airSprintSize_t(stmp2, sizeRed)); return 1; } /* also handles nio->byteSkip == -N-1 signifying extra N bytes at end */ - memcpy(_data, buff + sizeRed - sizeData - (-nio->byteSkip - 1), sizeData); + memcpy(_data, buff + sizeRed - sizeData - backwards, sizeData); airArrayNuke(buffArr); } else { /* no negative byteskip: after byteskipping, we can read directly Modified: teem/trunk/src/nrrd/read.c =================================================================== --- teem/trunk/src/nrrd/read.c 2012-10-03 18:36:38 UTC (rev 5703) +++ teem/trunk/src/nrrd/read.c 2012-10-03 19:05:29 UTC (rev 5704) @@ -281,7 +281,7 @@ return 1; } if (nio->byteSkip < 0) { - unsigned long backwards; + long backwards; if (nrrdEncodingRaw != nio->encoding) { biffAddf(NRRD, "%s: can do backwards byte skip only in %s " "encoding, not %s", me, @@ -295,8 +295,9 @@ bsize = nrrdElementNumber(nrrd)/_nrrdDataFNNumber(nio); bsize *= nrrdElementSize(nrrd); /* backwards is (positive) number of bytes AFTER data that we ignore */ - backwards = AIR_CAST(unsigned long, -nio->byteSkip - 1); - if (fseek(dataFile, -AIR_CAST(long, bsize + backwards), SEEK_END)) { + backwards = -nio->byteSkip - 1; + /* HEY what if bsize fits in size_t but not in (signed) long? */ + if (fseek(dataFile, -AIR_CAST(long, bsize) - backwards, SEEK_END)) { char stmp[AIR_STRLEN_SMALL]; biffAddf(NRRD, "%s: failed to fseek(dataFile, %s, SEEK_END)", me, airSprintSize_t(stmp, bsize)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |