Fix wild-pointer crash in RadarClass::Plot_Radar_Pixel on LP64 (radar/Comms Center) - #2
Merged
Merged
Conversation
The icon-set header stores 32-bit offsets (IControl_Type uses int32_t fields, guarded by static_assert(sizeof == 32)). Plot_Radar_Pixel read the "Icons" (+12) and "Map" (+28) offsets into a `long` via sizeof(offset). On LP64 (arm64 macOS/iOS) `long` is 8 bytes, so each read grabbed 4 valid bytes plus 4 bytes of the following field, producing a huge bogus offset and a wild pointer that crashed in Mem_Copy / Buffer_To_Page. Only triggers on the zoomed-in radar path (ZoomFactor > 1), e.g. after placing a Communications Center on a small map. Use int32_t for the offset so exactly 4 bytes are read, matching the IControl_Type field type and the accessor-based paths (Get_Icon_Set_Map / Get_Icon_Set_Icondata) used elsewhere. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
dk8827
force-pushed
the
fix/radar-icon-offset-lp64
branch
from
July 12, 2026 06:51
c161f18 to
3e1499d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On 64-bit builds (arm64 macOS/iOS), placing a Communications Center (which enables the radar minimap) crashes with
EXC_BAD_ACCESSon a wild pointer. Backtrace:Root cause
In the zoomed-in radar path (
ZoomFactor > 1),Plot_Radar_Pixelreads icon-set header offsets by hand:The icon-set header stores 32-bit offsets —
IControl_Typeusesint32_tfields and is guarded bystatic_assert(sizeof(IControl_Type) == 32), withIconsat +12 andMapat +28. Butoffsetis along, and on LP64sizeof(long) == 8, so eachMem_Copyreads 4 valid bytes plus 4 bytes of the following field. The result is a huge bogus offset →ptr + offsetis a wild pointer → crash inMem_Copy/Buffer_To_Page.It only triggers when the radar is zoomed in (
ZoomFactor > 1, i.e. smaller maps), which is why normal play is fine until the Comms Center turns the minimap on.Fix
Read exactly 4 bytes by making
offsetanint32_t, matching theIControl_Typefield type and the accessor-based paths (Get_Icon_Set_Map/Get_Icon_Set_Icondata) used elsewhere:int32_t offset;Verified by placing a Communications Center on a map that previously crashed on the arm64 macOS build.
🤖 Generated with Claude Code