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

Prevent possible nullptr crash #56405

Merged
merged 4 commits into from
Mar 29, 2022
Merged

Conversation

RoyBerube
Copy link
Contributor

Summary

Bugfixes "Prevent possible nullptr crash"

Purpose of change

Fixes #56382
Fixes #56389

Describe the solution

A pointer that can be a nullptr was being referenced, causing a crash when viewing a shoulder strap mod or its recipe. This avoids the use of the pointer when nullptr - behaviour is the same as in other sections of code that use the same pointer.

Describe alternatives you've considered

Testing

Viewing the recipe or shoulder strap item causes no problems. Viewed all recipes with no crashes.

Additional context

@github-actions github-actions bot added the [C++] Changes (can be) made in C++. Previously named `Code` label Mar 27, 2022
src/item.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Mar 27, 2022
Copy link
Member

@NetSysFire NetSysFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor whitespace changes so it is consistent with existing whitespace

src/item.cpp Outdated Show resolved Hide resolved
src/item.cpp Outdated Show resolved Hide resolved
@NetSysFire NetSysFire added Info / User Interface Game - player communication, menus, etc. <Bugfix> This is a fix for a bug (or closes open issue) labels Mar 27, 2022
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 27, 2022
RoyBerube and others added 2 commits March 27, 2022 18:25
Co-authored-by: NetSysFire <59517351+NetSysFire@users.noreply.github.com>
Co-authored-by: NetSysFire <59517351+NetSysFire@users.noreply.github.com>
@Inglonias
Copy link
Contributor

Inglonias commented Mar 29, 2022

I'm curious what it was about shoulder straps in particular that causes this to happen. Is it because shoulder straps aren't technically armor? We don't explicitly check for nullptr elsewhere in this method, so it might be worth tweaking it just to make the code fit in a little better.

@ZhilkinSerg ZhilkinSerg merged commit 0b63322 into CleverRaven:master Mar 29, 2022
@RoyBerube RoyBerube deleted the strap-crash branch March 29, 2022 16:13
@RoyBerube
Copy link
Contributor Author

@Inglonias The call to find_armor_data() returns a nullptr if the item has no armor data. Failure to check if it was a nullptr caused the crash.

mscottnelson pushed a commit to mscottnelson/Cataclysm-DDA that referenced this pull request Mar 31, 2022
Co-authored-by: NetSysFire <59517351+NetSysFire@users.noreply.github.com>
@RoyBerube RoyBerube mentioned this pull request Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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` Info / User Interface Game - player communication, menus, etc. json-styled JSON lint passed, label assigned by github actions
Projects
None yet
5 participants