From 99f8989f0c30ed794ea7bd1075590f524b79c7cd Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 12 Sep 2024 06:49:20 +0100 Subject: [PATCH] Codefix: Implement explicit ByteReader::PeekDWord() instead of type-punning pointer. (#12928) (cherry picked from commit 9631c68ce61dbafce7d1d05c5ca66ea7eafb8662) # Conflicts: # src/newgrf.cpp --- src/newgrf.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 8eeb3747f5..b3bdf1b805 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -12,6 +12,7 @@ #include #include "newgrf_internal.h" +#include "core/backup_type.hpp" #include "core/container_func.hpp" #include "core/bit_cast.hpp" #include "debug.h" @@ -158,6 +159,12 @@ public: return val | (ReadWord() << 16); } + uint32_t PeekDWord() + { + AutoRestoreBackup backup(this->data, this->data); + return this->ReadDWord(); + } + uint32_t ReadVarSize(uint8_t size) { switch (size) { @@ -1950,7 +1957,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons NewGRFSpriteLayout *dts = &statspec->renderdata.emplace_back(); dts->consistent_max_offset = UINT16_MAX; // Spritesets are unknown, so no limit. - if (buf.HasData(4) && *(unaligned_uint32*)buf.Data() == 0) { + if (buf.HasData(4) && buf.PeekDWord() == 0) { buf.Skip(4); extern const DrawTileSprites _station_display_datas_rail[8]; dts->Clone(&_station_display_datas_rail[t % 8]);