remove obj guard from stone_missile(obj) macro

Checking the callers:
toss_up() would have segfaulted prior to use of stone_missile() if obj were NULL.
thitu() now has a guard prior to use of stone_missile()
ohitmon() would have crashed from earlier dereference otmp->dknown if it were NULL,
   otmp arg is declared nonnull
thitm() now has a guard prior to use of stone_missile().
hmon_hitmon_do_hit() null obj takes a different code path than the code path
    using stone_missile(); comment asserting that added
This commit is contained in:
nhmall
2023-12-16 07:58:44 -05:00
parent 0099098d35
commit 70dcab833d
6 changed files with 11 additions and 9 deletions

View File

@@ -257,7 +257,7 @@ struct obj {
/* 'missile' aspect is up to the caller and does not imply is_missile();
rings might be launched as missiles when being scattered by an explosion */
#define stone_missile(o) \
((o) && (objects[(o)->otyp].oc_material == GEMSTONE \
((objects[(o)->otyp].oc_material == GEMSTONE \
|| (objects[(o)->otyp].oc_material == MINERAL)) \
&& (o)->oclass != RING_CLASS)

View File

@@ -17,8 +17,7 @@
static struct artifact *get_artifact(struct obj *) NONNULL; /* never returns null */
/* #define get_artifact(o) \
(((o) && ((o)->artifact > 0 && (o)->artifact < AFTER_LAST_ARTIFACT)) \
? &artilist[(int) (o)->oartifact] \
(((o) && (o)->oartifact) ? &artilist[(int) (o)->oartifact] \
: &artilist[ART_NONARTIFACT]) */
static boolean bane_applies(const struct artifact *, struct monst *) NONNULLARG12;
@@ -2546,8 +2545,7 @@ is_art(struct obj *obj, int art)
}
/* #define get_artifact(o) \
(((o) && ((o)->artifact > 0 && (o)->artifact < AFTER_LAST_ARTIFACT)) \
? &artilist[(int) (o)->oartifact] \
(((o) && (o)->oartifact) ? &artilist[(int) (o)->oartifact] \
: &artilist[ART_NONARTIFACT]) */
static struct artifact *

View File

@@ -13,7 +13,7 @@ static int throw_ok(struct obj *);
static void autoquiver(void);
static struct obj *find_launcher(struct obj *);
static int gem_accept(struct monst *, struct obj *);
static boolean toss_up(struct obj *, boolean);
static boolean toss_up(struct obj *, boolean) NONNULLARG1;
static void sho_obj_return_to_u(struct obj * obj);
static struct obj *return_throw_to_inv(struct obj *, long, boolean,
struct obj *);

View File

@@ -120,7 +120,8 @@ thitu(
if (is_acid && Acid_resistance) {
pline("It doesn't seem to hurt you.");
monstseesu(M_SEEN_ACID);
} else if (stone_missile(obj) && passes_rocks(gy.youmonst.data)) {
} else if (obj && stone_missile(obj) && passes_rocks(gy.youmonst.data)) {
/* use 'named' as an approximation for "hitting from above";
we avoid "passes through you" for horizontal flight path
because missile stops and that wording would suggest that
@@ -323,6 +324,7 @@ ohitmon(
boolean vis, ismimic, objgone;
struct obj *mon_launcher = gm.marcher ? MON_WEP(gm.marcher) : NULL;
/* assert(otmp != NULL); */
gn.notonhead = (gb.bhitpos.x != mtmp->mx || gb.bhitpos.y != mtmp->my);
ismimic = M_AP_TYPE(mtmp) && M_AP_TYPE(mtmp) != M_AP_MONSTER;
vis = cansee(gb.bhitpos.x, gb.bhitpos.y);

View File

@@ -67,7 +67,7 @@ static void untrap_box(struct obj *, boolean, boolean);
#if 0
static void join_adjacent_pits(struct trap *);
#endif
static boolean thitm(int, struct monst *, struct obj *, int, boolean);
static boolean thitm(int, struct monst *, struct obj *, int, boolean) NONNULLARG2;
static void maybe_finish_sokoban(void);
static const char *const a_your[2] = { "a", "your" };
@@ -6345,7 +6345,7 @@ thitm(
pline("%s is almost hit by %s!", Monnam(mon), doname(obj));
} else {
int dam = 1;
boolean harmless = (stone_missile(obj) && passes_rocks(mon->data));
boolean harmless = (obj && stone_missile(obj) && passes_rocks(mon->data));
if (obj && cansee(mon->mx, mon->my))
pline("%s is hit by %s%s", Monnam(mon), doname(obj),

View File

@@ -1324,6 +1324,8 @@ hmon_hitmon_do_hit(
if (!obj) { /* attack with bare hands */
hmon_hitmon_barehands(hmd, mon);
} else {
/* obj is not NULL here because of the !obj check in this if block,
, so no guard is needed ahead of stone_missile(obj) */
/* stone missile does not hurt xorn or earth elemental, but doesn't
pass all the way through and continue on to some further target */
if ((hmd->thrown == HMON_THROWN