From e0360616809f0f00834009161e54df0d39ef831c Mon Sep 17 00:00:00 2001 From: jnemeth Date: Wed, 29 Mar 2006 01:18:39 +0000 Subject: Fix Coverity issue 2584 -- USE_AFTER_FREE and issue 889 -- FORWARD_NULL. Approved by christos@. --- hack/hack.fight.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'hack') diff --git a/hack/hack.fight.c b/hack/hack.fight.c index 3929a3c2..86dd2f6b 100644 --- a/hack/hack.fight.c +++ b/hack/hack.fight.c @@ -1,4 +1,4 @@ -/* $NetBSD: hack.fight.c,v 1.6 2003/04/02 18:36:36 jsm Exp $ */ +/* $NetBSD: hack.fight.c,v 1.7 2006/03/29 01:18:39 jnemeth Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -63,7 +63,7 @@ #include #ifndef lint -__RCSID("$NetBSD: hack.fight.c,v 1.6 2003/04/02 18:36:36 jsm Exp $"); +__RCSID("$NetBSD: hack.fight.c,v 1.7 2006/03/29 01:18:39 jnemeth Exp $"); #endif /* not lint */ #include "hack.h" @@ -252,10 +252,12 @@ hmon(mon, obj, thrown) /* return TRUE if mon still alive */ freeinv(obj); setworn((struct obj *) 0, obj->owornmask); obfree(obj, (struct obj *) 0); + obj = NULL; tmp++; } } - if (mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD && + if (mon->data->mlet == 'O' && obj != NULL && + obj->otyp == TWO_HANDED_SWORD && !strcmp(ONAME(obj), "Orcrist")) tmp += rnd(10); } else @@ -319,11 +321,13 @@ hmon(mon, obj, thrown) /* return TRUE if mon still alive */ mon->mfleetim += 10 * rnd(tmp); } if (!hittxt) { - if (thrown) + if (thrown) { /* this assumes that we cannot throw plural things */ + if (obj == NULL) + panic("thrown non-object"); hit(xname(obj) /* or: objects[obj->otyp].oc_name */ , mon, exclam(tmp)); - else if (Blind) + } else if (Blind) pline("You hit it."); else pline("You hit %s%s", monnam(mon), exclam(tmp)); -- cgit v1.2.3-56-ge451