chuck
chuck copied to clipboard
FileIO write( int, int ) in binary mode potentially incorrect
(binary mode only) presently Chuck_IO_File::write( t_CKINT val, t_CKINT flags )
simply writes starting at the pointer address of val
and does not take into account size of architecture (64 vs 32 bit) nor endianness:
else if (m_flags & TYPE_BINARY) {
int nBytes = 4;
if(flags & INT8) nBytes = 1;
else if(flags & INT16) nBytes = 2;
else if(flags & INT32) nBytes = 4;
m_io.write( (char *)&val, nBytes );
}
possibly the values written should be copied into appropriately sized variables, and possibly byte-swapped (this need to also take into account how FileIO binary mode read expects endianness in ints), before written to file.
cc @nshaheed @spencersalazar