Repository navigation
Conversation
newSprite() allocated SimSprite with newPtr (malloc) and then assigned to its std::string name member while the member held unconstructed storage, which is undefined behaviour that worked on a zero-filled heap. Construct the object in place over the existing pooled allocation. Micropolis::callback, mapBase and mopBase have the same problem: all three are read before assignment in guarded paths (setCallback deletes the previous callback; initMapArrays guards on the base pointers), so give them NULL default initializers.
jquast
marked this pull request as ready for review
September 29, 2026 17:15
This branch has not been deployed
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.
A series of memory violations, each found with the new
make asanbuild:SimSpriteallocated bynewPtrinnewSprite()is left unconstructedMicropolis::callback,mapBaseandmopBaseare read before assignment#12 contains the same fixes, and this PR also Closes #11. It allocates the sprite with
new SimSprite(); this constructs it over the pooled allocation. It setscallbackin the constructor; this initializes it where it is declared, along withmapBaseandmopBase.Detected by running
sim smoke:Depends on #15 (the loader fix) and #16 (the
make asantarget) to run the commands above.