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

Fix using a null item in target_handler::target_ui #36137

Merged
merged 3 commits into from
Dec 16, 2019

Conversation

BevapDin
Copy link
Contributor

SUMMARY: None

Basically if the function was not given a valid pointer, it would just use g->u.weapon, which is often a null item (not wielding anything is required to fire a vehicle turret). In turn, some functions got called with that null item and some of them blindly assumes it will be a gun item and simply crashed when it wasn't.

Fixes #35434.

src/ranged.cpp Outdated
@@ -1324,8 +1323,9 @@ std::vector<tripoint> target_handler::target_ui( player &pc, target_mode mode,
aim_mode = aim_types.begin();
}

int num_instruction_lines = draw_targeting_window( w_target, relevant->tname(),
mode, ctxt, aim_types, tiny );
// @TODO this assumes that relevant == null means firigin turrets, but that may not
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// @TODO this assumes that relevant == null means firigin turrets, but that may not
// @TODO this assumes that relevant == null means firing turrets, but that may not

src/ranged.cpp Outdated
@@ -1427,7 +1427,9 @@ std::vector<tripoint> target_handler::target_ui( player &pc, target_mode mode,
if( !compact ) {
line_number++;
}
if( mode == TARGET_MODE_FIRE || mode == TARGET_MODE_TURRET_MANUAL ) {
// Assumes that relevant == null means firing turrets (maybe even multiple at once),
// so printing their firing mode / ammo / ... of one of them is missleading.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// so printing their firing mode / ammo / ... of one of them is missleading.
// so printing their firing mode / ammo / ... of one of them is misleading.

src/ranged.cpp Outdated
@@ -1470,7 +1472,9 @@ std::vector<tripoint> target_handler::target_ui( player &pc, target_mode mode,
c_red, '*' );
}

if( mode == TARGET_MODE_FIRE ) {
// Assumes that relevant == null means firing turrets (maybe even multiple at once),
// so printing their firing mode / ammo / ... of one of them is missleading.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// so printing their firing mode / ammo / ... of one of them is missleading.
// so printing their firing mode / ammo / ... of one of them is misleading.

@ZhilkinSerg ZhilkinSerg added <Bugfix> This is a fix for a bug (or closes open issue) Ranged Ranged (firearms, bows, crossbows, throwing), balance, tactics [C++] Changes (can be) made in C++. Previously named `Code` labels Dec 16, 2019
The pointer was dereferenced without any null-check anyway, so the function pretty much expects a valid pointer. This makes it clear to the caller.
Call `Character::has_item` instead of going the route via `get_item_position` (returns an invalid index) and calling `i_at` (which returns a null item when the input is an invalid index).
Instead of assuming it is `pc.weapon`. Note that `pc.weapon` may be a null item anyway (character needs to wield nothing when they want to fire a vehicle turret).
This in turn means a null item was given to some functions around, and not all of them would handle this well. Some assumed the input was always a gun item.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Ranged Ranged (firearms, bows, crossbows, throwing), balance, tactics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault when switching firing modes in a vehicle using multiple turrets
4 participants