Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed segfault when monster tries to grab-drag another monster out of reality bubble #76058

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

HadeanLake
Copy link
Contributor

Summary

Bugfixes "Fixed segfault when monster tries to grab-drag another monster out of reality bubble"

Purpose of change

fix #75793

I believe, someone was writing the code for selecting a random square, then discovered that function random_entry already exists and decided to use it instead, but forgot to remove already written and no longer needed code

There are 2 lines of code at mattack_actors.cpp:617

            std::set<tripoint>::iterator intersect_iter = intersect.begin();
            std::advance( intersect_iter, rng( 0, intersect.size() - 1 ) );

Those lines are optimized away by some configs since variable intersect_iter is never used after this

set intersect is not checked for being empty.
intersect is empty when monster that does dragging is right at the edge of reality bubble and the next tile in the direction of dragging is outside of it.
when intersect is empty second line causes segfault (if built for linux using gcc or built for windows using mxe) or debug assetion failure "cannot decrement begin map/set iterator" (if built using msvc for debugging)

this crash does not occur in android and msvc-release builds

function random_entry called on the next line after those 2 has container.empty() check, 2 same lines and return of it is assigned to target_square and actually used down the code

Describe the solution

remove redundant code

Describe alternatives you've considered

Testing

Compiled, verified that monsters can grab and drag and save from linked issue does not trigger segfault

Additional context

Should be backported to 0.H-branch since those lines are present there

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Aug 30, 2024
@inogenous
Copy link
Contributor

inogenous commented Aug 30, 2024

Wow, that's such a nice find. Fixing a bug by only removing (unused) code, thereby also making it easier to maintain. Hats off to you @HadeanLake ! 🥇

@akrieger akrieger merged commit 13f5534 into CleverRaven:master Aug 30, 2024
27 checks passed
@HadeanLake HadeanLake deleted the seg1 branch August 30, 2024 19:50
GuardianDll added a commit that referenced this pull request Aug 30, 2024
@GuardianDll GuardianDll mentioned this pull request Aug 30, 2024
ZhilkinSerg pushed a commit that referenced this pull request Aug 30, 2024
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.H Backported astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault when monster tries to grab-drag another monster out of reality bubble
4 participants