follow-up for put_saddle_on_mon()
Commit 1acc2727 helped ensure that the which_armor(mtmp, W_SADDLE)
test at the top of put_saddle_on_mon() wouldn't lead to an obj
leak.
This commit covers off the adjacent can_saddle() test in
put_saddle_on_mon(), because if that failed, it could also lead
to a memory leak of the saddle obj passed by the caller.
- have put_saddle_on_mon() create and use its own saddle obj
if a NULL saddle obj is passed, instead of having to do that
in the caller.
- where an existing saddle obj needs to be passed from the caller,
ensure that the caller has done its own can_saddle(mon) check prior
to calling put_saddle_on_mon(), so that the can_saddle() test
in put_saddle_on_mon() won't fail.
- lastly, add an impossible() to put_saddle_on_mon() to catch
a failure when a saddle obj is passed from the caller and either
test has failed, just in case. That should not happen with any of
the existing cases now, but it will provide some bullet-proofing
for new code, new callers.
This commit is contained in:
@@ -3056,7 +3056,7 @@ extern struct obj *findgold(struct obj *) NO_NNARGS;
|
||||
extern void rider_cant_reach(void);
|
||||
extern boolean can_saddle(struct monst *) NONNULLARG1;
|
||||
extern int use_saddle(struct obj *) NONNULLARG1;
|
||||
extern void put_saddle_on_mon(struct obj *, struct monst *) NONNULLARG12;
|
||||
extern void put_saddle_on_mon(struct obj *, struct monst *) NONNULLARG2;
|
||||
extern boolean can_ride(struct monst *) NONNULLARG1;
|
||||
extern int doride(void);
|
||||
extern boolean mount_steed(struct monst *, boolean) NO_NNARGS;
|
||||
|
||||
Reference in New Issue
Block a user