Prevent negative array index for floor_cache #75453
Merged
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.
Summary
Bugfixes "Prevent negative array index for floor_cache"
Purpose of change
Prevents referencing
floor_cache
using out-of-bounds array indexes such as negative values and values greater than 132. Using out-of-bound indexes for this array previously caused crashes when compiled with-D_GLIBCXX_ASSERTIONS
.Fixes #75039 .
Describe the solution
The function
map::dont_draw_lower_floor
is, for example, called fromcata_tiles::draw
with values such asp=(0,132,0)
orp=(-36,5,0)
. Such values can be seen when zooming out withZ
sodraw
also handles tiles that do not fit into local bub coordinates.Previous crash happened here:
Describe alternatives you've considered
inbounds
for each tile during thedraw
call since that might have an effect on performance. It might be possible to do some smarter out-of-bounds checking?_ib
coordinates, which would make a bug such as this a compile-time problem instead. But that's for a future refactoring.Testing
-D_GLIBCXX_ASSERTIONS
.master
since this function is called withp=(-36,5,0)
.Additional context