Skip to content

Commit

Permalink
Riotbot attack: Check if wielded weapon is null before using (#59298)
Browse files Browse the repository at this point in the history
* Riotbot attack: Check if wielded weapon is null before using

The game would occasionally crash when in presence of a riotbot.
Running a debug build of the game relvealed the cause -
mattack::riotbot would use get_wielded_item()->typeId() without
checking if it was actually getting an item.
The function will now check the returned item_location
like other code using get_wielded_item() does.

References #58666

* Add parentheses to the logical expression
  • Loading branch information
prilr authored Jul 16, 2022
1 parent 09ce0f8 commit 12f29ef
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4985,17 +4985,20 @@ bool mattack::riotbot( monster *z )

// Already arrested?
// And yes, if the player has no hands, we are not going to arrest them.
if( foe != nullptr &&
( foe->get_wielded_item()->typeId() == itype_e_handcuffs || !foe->has_two_arms_lifting() ) ) {
z->anger = 0;
if( foe != nullptr ) {
item_location foe_weapon = foe->get_wielded_item();

if( calendar::once_every( 25_turns ) ) {
sounds::sound( z->pos(), 10, sounds::sound_t::electronic_speech,
_( "Halt and submit to arrest, citizen! The police will be here any moment." ), false, "speech",
z->type->id.str() );
}
if( foe_weapon && ( foe_weapon->typeId() == itype_e_handcuffs || !foe->has_two_arms_lifting() ) ) {
z->anger = 0;

return true;
if( calendar::once_every( 25_turns ) ) {
sounds::sound( z->pos(), 10, sounds::sound_t::electronic_speech,
_( "Halt and submit to arrest, citizen! The police will be here any moment." ), false, "speech",
z->type->id.str() );
}

return true;
}
}

if( z->anger < z->type->agro ) {
Expand Down

0 comments on commit 12f29ef

Please sign in to comment.