Skip to content

Commit

Permalink
Fix crash when NPC gives player equipment
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox authored and Rivet-the-Zombie committed Apr 12, 2020
1 parent 0f1f2f2 commit a07ce29
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,20 @@ void talk_function::give_equipment( npc &p )
{
std::vector<item_pricing> giving = npc_trading::init_selling( p );
int chosen = -1;
while( chosen == -1 && giving.size() > 1 ) {
while( chosen == -1 && !giving.empty() ) {
int index = rng( 0, giving.size() - 1 );
if( giving[index].price < p.op_of_u.owed ) {
chosen = index;
} else {
giving.erase( giving.begin() + index );
}
giving.erase( giving.begin() + index );
}
if( giving.empty() ) {
popup( _( "%s has nothing to give!" ), p.name );
return;
}
if( chosen == -1 ) {
if( chosen < 0 || static_cast<size_t>( chosen ) >= giving.size() ) {
debugmsg( "Chosen index is outside of available item range!" );
chosen = 0;
}
item it = *giving[chosen].loc.get_item();
Expand Down

0 comments on commit a07ce29

Please sign in to comment.