DarkRadiant icon indicating copy to clipboard operation
DarkRadiant copied to clipboard

Refactor code and fixed bug on x64

Open GermanAizek opened this issue 4 years ago • 4 comments

@codereader review code please

GermanAizek avatar Oct 01 '21 13:10 GermanAizek

Thank you!

codereader avatar Oct 01 '21 13:10 codereader

Can you give me a description of the problem you fixed in the picomodel library? I want to add an entry to the bugtracker for the release changelog.

codereader avatar Oct 01 '21 13:10 codereader

Can you give me a description of the problem you fixed in the picomodel library? I want to add an entry to the bugtracker for the release changelog.

@codereader, this change applies only to 64 bit systems. bug is a transformation of a dangerous explicit type pointer typedef picoByte_t picoColor_t[ 4 ]; -> unsigned char picoColor_t[ 4 ]; it turns out that we unsigned char** converts to int** on 32 and 64 bit systems there will be different values. You can check this piece of code with debug mode on Win32 and x64 The size of the ptrdiff_t is equal in both systems

GermanAizek avatar Oct 01 '21 14:10 GermanAizek

I don't really like that particular piece of code, but isn't this just loading the 4 bytes of memory occupied by the picoColor array by casting the location to int* and de-referencing that? sizeof(int) is 4 bytes on both platforms, as are 4x unsigned chars. By casting it to ptrdiff_t* it will compare 8 bytes - wouldn't this cause an overflow when accessing that memory at color[j]?

codereader avatar Oct 01 '21 16:10 codereader