Error in TGAWrite Header.
In the event hdr.map_t is zero, incorrect bytes in the
tmp array are cleared. The code below shows the
correction in the memset function to eliminate this error.
if (tga->hdr.map_t != 0) {
tmp[1] = 1;
tmp[3] = tga->hdr.map_first % 256;
tmp[4] = tga->hdr.map_first /256;
tmp[5] = tga->hdr.map_len % 256;
tmp[6] = tga->hdr.map_len / 256;
tmp[7] = tga->hdr.map_entry;
} else {
tmp[1] = 0;
memset(tmp + 3, 0, 5); // Error in
original library
}
The incorrect statement was:
memset(tmp + 4, 0, 5);
which left tmp[3] undefined when hdr.map_t was zero.
Two other possible errors exist in the processing of RLE
data. When the TGA_RLE_ENCODE flag is set, the read
and write functions adjust the hdr.img_t value with -=8
and +=8 respectively. However, it is possible that this
bit is already set in the header leading to an error. I
propose using &= ~8 and |= 8 respectively. Although
this could also be corrected by clearly describing in the
API documents that the RLE codes should not be set in
the header structure but only by using the flags.
One other small issue that should be corrected in the
documentation is the proper use of the open commands.
The "w" and "r" options should be avoided on Win
machines as they can expand/contract CR-LF, and FL
characters in the data stream.
email: bclodfelter@ameritech.net
Hey,
I forked this project on GitHub and fixed some bugs on the way.
I fixed the non-initialization of tmp[3] (verified using valgrind).
For the moment, the documentation is removed but will return sometime.
The fork is at https://github.com/madebr/libtga.