IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Opened 21 years ago

Closed 21 years ago

Last modified 20 years ago

#583 closed defect (fixed)

psVector.nalloc casting errors

Reported by: eugene Owned by: robert.desonia@…
Priority: high Milestone:
Component: mathtypes Version: 0.8.0
Severity: normal Keywords:
Cc:

Description

in several places, a psVector is created to point at an existing block of data.

Since psVector.nalloc is a const, this value is set with code of the form:

*(type *)&data = value

I have found a number of places in which this technique is used for
psVector.nalloc where 'type' is set to 'int' rather than 'long'. this causes
nasty errors on 64bit machines where int and long are different sizes:

the following lines have this error:

./imageops/psImagePixelExtract.c:409: imgVec->n = *(int*)&imgVec->nalloc

numCols;

./imageops/psImagePixelExtract.c:413: maskVec->n =
*(int*)&maskVec->nalloc = numCols;
./imageops/psImageStats.c:66: *(int*)&junkData->nalloc = in->numRows *
in->numCols;
./imageops/psImageStats.c:90: *(int*)&junkMask->nalloc =
mask->numRows * mask->numCols;
./imageops/psImageStats.c:139: *(int*)&junkData->nalloc = in->numRows *
in->numCols;
./imageops/psImageStats.c:163: *(int*)&junkMask->nalloc =
mask->numRows * mask->numCols;
./math/psStats.c:2337: *(int *)&newHist->bounds->n = newHist->bounds->nalloc;
./math/psStats.c:2386: *(int *)&newHist->bounds->n = newHist->bounds->nalloc;

Perhaps this concept needs to be converted into a psLib function which would
isolate the change to one location. I propose something like:

psVector *psVectorAssign (psVector *in, void *data, long nBytes, psElemType type);

Change History (1)

comment:1 by robert.desonia@…, 21 years ago

Resolution: fixed
Status: newclosed

The problem here is that the *(type*)&data = value syntax depends on the type of data, which in this
case, changes. This is a problem not just in the functions you identified, but in many other locations as
well.

I make this less likely to happen again, I searched for '*(int', '*(long' and '*(float) in the code and
replaced those lines with macros defined along side of the struct being referenced. This allows a const
item in a struct to be changed in type and only the macro directly following it needs to also be
modified.

The particular error here was that psVector's nalloc changed type and only psVector.c was changed as
far as the *(type*)& syntax was concerned. This has been fixed via the definition of a
P_PSVECTOR_SET_NALLOC macro that appears just after the struct definition and is used everywhere
the nalloc attribute is set.

-rdd

Note: See TracTickets for help on using tickets.