1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 13:33:02 +01:00

Fix strict aliasing violations

Compiler only guarantees proper accesses to variables when using
variable's native type or `char` (i.e. single byte type) [1].

This commit fixes violations of this rule. In most cases changing code
to a simple cast was enough, some required a bit deeper modifications.

This fixes #2596.

[1] http://blog.qt.io/blog/2011/06/10/type-punning-and-strict-aliasing/
This commit is contained in:
Michał Janiszewski
2015-12-31 09:16:44 +01:00
parent db95b3ada3
commit 8a5d066efe
18 changed files with 98 additions and 77 deletions

View File

@@ -242,7 +242,11 @@ void platform_draw()
if (pitch == (width * 2) + padding) {
uint16 *dst = pixels;
for (int y = height; y > 0; y--) {
for (int x = width; x > 0; x--) { *dst++ = *(uint16 *)(&gPaletteHWMapped[*src++]); }
for (int x = width; x > 0; x--) {
const uint8 lower = *(uint8 *)(&gPaletteHWMapped[*src++]);
const uint8 upper = *(uint8 *)(&gPaletteHWMapped[*src++]);
*dst++ = (lower << 8) | upper;
}
dst = (uint16*)(((uint8 *)dst) + padding);
}
}