2001.06.20 16:53 "Possible bug with Big versus Little Endian", by Neil Talsania

2001.06.20 16:53 "Possible bug with Big versus Little Endian", by Neil Talsania


I have encountered a problem when running my application on a big endian versus little endian machine. The file I am creating has the SMIN and SMAX tags set. The image data is 8bps so the SMIN and SMAX tags are of type BYTE. There are 3 bands in the file, so there are 3 values in the SMIN and SMAX tag (of course all the same value) The file that I am creating is a big endian type file (regardless of architecture of system). The code works great when I create the file on a big endian machine and then read it on a big endian machine. But it does not work if I create the file on a little endian machine. The error that I get is that the values must match on all three bands for SMAX.

I stepped through the code in the debugger, and I think that I have the problem isolated, and put in a fix that seems to work. The problem seems to be that the SMAX tag has 3 BYTE values that are stored in byte 0,1,2 of the char * which is then memcpy into the integer offset variable. Then, when the header is actually written, the data is flipped because the file is big endian, but the architecture is little endian. But then when I go to read this file on the big endian machine I get the error. The reason is that the reading the big endian file on a big endian machine, I will read the offset, and now my values are in the wrong bytes, because the read code is only dependent on the file type.

The fix that I put in is in the write. In the TIFFWriteByteArray function, if I am less than 4 bytes instead of just doing the memcpy, I check to see if I am going to be swapped on write. IF not then I do the memcpy, but if so, then I swap the bytes here, then everything seems to work.

If anyone has any opinions on why my fix is not the right thing, please let me know. If I get a chance to get more detail form the one system moved over to where I can include it, I will probably create a new bug report for this. I realize that if I could provide more information, my problem might have a beter chance of getting resolved.

Neil Talsania