Skip to content
Permalink
Browse files

more robust NULL pointer checking in item.cpp

  • Loading branch information...
placeybordeaux committed Nov 30, 2013
1 parent c985adf commit f0e73267e95703c26ab5d29bd162e26fad531e41
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/item.cpp
@@ -359,7 +359,7 @@ std::string item::info(bool showtext, std::vector<iteminfo> *dump, game *g, bool
if ( g != NULL && debug == false &&
( g->debugmon == true || g->u.has_artifact_with(AEP_SUPER_CLAIRVOYANCE) )
) debug=true;
if( !is_null() )
if( !is_null() && g != NULL)
{
dump->push_back(iteminfo("BASE", _("Volume: "), "", volume(), true, "", false, true));
dump->push_back(iteminfo("BASE", _(" Weight: "), "", g->u.convert_weight(weight()), false, "", true, true));
@@ -1432,7 +1432,11 @@ std::string item::get_material(int m) const
if (corpse != NULL && typeId() == "corpse" )
return corpse->mat;

if ( is_null())
return "NULL type";

return (m==2)?type->m2:type->m1;

}

bool item::made_of(phase_id phase) const
@@ -2213,7 +2217,7 @@ bool item::reload(player &u, char ammo_invlet)
item *ammo_to_use = (ammo_invlet != 0 ? &u.inv.item_by_letter(ammo_invlet) : NULL);

// also check if wielding ammo
if (ammo_to_use->is_null()) {
if (ammo_to_use == NULL || ammo_to_use->is_null()) {
if (u.is_armed() && u.weapon.is_ammo() && u.weapon.invlet == ammo_invlet)
ammo_to_use = &u.weapon;
}

1 comment on commit f0e7326

@Savidiy

This comment has been minimized.

Copy link
Contributor

commented on f0e7326 Dec 1, 2013

Hi!
350:
std::string item::info(bool showtext)
{
std::vector dummy;
return info(showtext, &dummy);
}

This code don't pass a game parameter. Not displays the properties in craft menu, review of items around and examine of cells.

Please sign in to comment.
You can’t perform that action at this time.