C
Chlikaflok
See, I have this code, I'm trying to open and run a MIDI file, and I'm
parsing the header to check it's integrity :
// Parse header info.
char chunkType[4];
char buffer[4];
SINT32 *length;
if ( !file_.read( chunkType, 4 ) ) goto error;
if ( !file_.read( buffer, 4 ) ) goto error;
length = (SINT32 *) &buffer;
if ( strncmp( chunkType, "MThd", 4 ) || ( *length != 6 ) )
{Error msgs and stuff}
SINT32 is a typedef for signed int
Using a perfectly good midi file, this segment of code should go right
past the IF block, because the buffer char array should contain ([0],
[0],[0],[6]), which it does. But when I evaluate the length expression
in the IF clause, the value is exactly and always : 100663296.
As I understand it, the 4-byte char array contains "00000006", which
when cast to int should read "6", correct me if I'm wrong. Using
buffer[3]instead of the *length evaluation in the IF resolves the
problem, but that way of using the buffer data is used all over the
library I'm using and I believe it was done that way for a reason.
Any help would be welcome,
Thx in advance for at least reading this,
Chlikaflok.
parsing the header to check it's integrity :
// Parse header info.
char chunkType[4];
char buffer[4];
SINT32 *length;
if ( !file_.read( chunkType, 4 ) ) goto error;
if ( !file_.read( buffer, 4 ) ) goto error;
length = (SINT32 *) &buffer;
if ( strncmp( chunkType, "MThd", 4 ) || ( *length != 6 ) )
{Error msgs and stuff}
SINT32 is a typedef for signed int
Using a perfectly good midi file, this segment of code should go right
past the IF block, because the buffer char array should contain ([0],
[0],[0],[6]), which it does. But when I evaluate the length expression
in the IF clause, the value is exactly and always : 100663296.
As I understand it, the 4-byte char array contains "00000006", which
when cast to int should read "6", correct me if I'm wrong. Using
buffer[3]instead of the *length evaluation in the IF resolves the
problem, but that way of using the buffer data is used all over the
library I'm using and I believe it was done that way for a reason.
Any help would be welcome,
Thx in advance for at least reading this,
Chlikaflok.