Skip to content

Commit

Permalink
Fix possible segfault caused by #2468 when guns are fired (#2516)
Browse files Browse the repository at this point in the history
* Update ranged.cpp

Fix dumb code I made

* Update src/ranged.cpp

Co-authored-by: scarf <[email protected]>

---------

Co-authored-by: scarf <[email protected]>
  • Loading branch information
KheirFerrum and scarf005 authored Mar 31, 2023
1 parent 662c8b4 commit 9fc83b6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,9 @@ int ranged::fire_gun( Character &who, const tripoint &target, int max_shots, ite

int shots = max_shots;
// Number of shots to fire is limited by the amount of remaining ammo
if( gun.ammo_required() && !ammo ) {
shots = std::min( shots, static_cast<int>( gun.ammo_remaining() / gun.ammo_required() ) );
} else {
shots = std::min( shots, ammo.get_item()->count() / gun.ammo_required() );
if( gun.ammo_required() ) {
const int ammo_left = ammo ? ammo.get_item()->count() : gun.ammo_remaining();
shots = std::min( shots, ammo_left / gun.ammo_required() );
}

// cap our maximum burst size by the amount of UPS power left
Expand Down

0 comments on commit 9fc83b6

Please sign in to comment.