That said, I will now do some ranting.
Fucking external code and your use of unsigned ints! I've tracked down the last two (*) of my nasty bugs in porting to 64 bit and both were because of people using unsigned ints for no good reason. (* = I think; you can never know that you found your last bug, much like you can never prove a physical theory right).
One was in the BMP reader code that I stole from MSDN years ago after getting fed up with not being able to load some weird formats (RLE4 or whatever). (BTW this is another rant - every god damn video game codebase I've ever used has some broken ass home-rolled BMP reader in it that only handles the most friendly and vanilla BMP formats; fucking don't roll your own broken ass shit when there are perfectly good fully functional ones you can take). Anyway, because it's MS code it uses the awful DWORD and UINT and all that shit. It actually had a number of little bugs that I fixed over the years, such as this one :
< dwSrcInc = ((dwWidth >> 3) + 3) & ~3; -> dwSrcInc = (((dwWidth+7) >> 3) + 3) & ~3;but the nasty one was the inherent type of dwSrcInc. BMP's of course can scan up or down so there's some code that does :
if ( normal ) dwSrcInc = pitch; else dwSrcInc = - pitch;Looks good, right? Well, sort of. Of course dwSrcInc is a DWORD. What happens when you put a negative in there ? Yeah, you're getting it. We then update the pointer like :
ptr += dwSrcInc;Well, this works out the way you want if the pointer is 32 bits, because the pointer math is done like an unsigned int add and it wraps. But when the pointer is 64 bits, you're adding not quite 4 billion to your pointer. No good.
While I'm at it, this is the list of nasty not-obvious stuff to watch out for that I made :
64-bit dangers : use of C-style casts, like : int x = (int) pointer; use of hard-coded sizes in mallocs : void ** ptrArray = malloc( 4 * count ); structs with pointers that are IO'd as bytes or otherwise converted to bytes as in unions etc use of 0xFFFFFFFF and similar use of (1<<31) as a flag bit in pointers struct packing changes ptrdiff_t is signed size_t is unsigned !! unions of mismatched sizes do not warn !!