static analyzer - shk.c

Add a couple of redundant tests for 'shkp = shop_keeper()' yielding
Null to pacify the static analyzer.

Make the paired calls to shkp = shop_keeper() and inhishop(shkp) look
more consistent.  Barring typos, the behavior hasn't been changed.
This commit is contained in:
PatR
2023-01-16 17:15:26 -08:00
parent 9b01ab2fd5
commit 9df4a38d65
2 changed files with 59 additions and 41 deletions

View File

@@ -629,7 +629,8 @@ u_entered_shop(char* enterstring)
if (!*enterstring) if (!*enterstring)
return; return;
if (!(shkp = shop_keeper(*enterstring))) { shkp = shop_keeper(*enterstring);
if (!shkp) {
if (!strchr(empty_shops, *enterstring) if (!strchr(empty_shops, *enterstring)
&& in_rooms(u.ux, u.uy, SHOPBASE) && in_rooms(u.ux, u.uy, SHOPBASE)
!= in_rooms(u.ux0, u.uy0, SHOPBASE)) != in_rooms(u.ux0, u.uy0, SHOPBASE))
@@ -2574,7 +2575,7 @@ unpaid_cost(
} }
#endif #endif
for (shop = u.ushops; *shop; shop++) { for (shop = u.ushops; *shop; shop++) {
if ((shkp = shop_keeper(*shop))) { if ((shkp = shop_keeper(*shop)) != 0) {
if ((bp = onbill(unp_obj, shkp, TRUE))) if ((bp = onbill(unp_obj, shkp, TRUE)))
amt = unp_obj->quan * bp->price; amt = unp_obj->quan * bp->price;
if (include_contents && Has_contents(unp_obj)) if (include_contents && Has_contents(unp_obj))
@@ -2891,12 +2892,12 @@ append_honorific(char *buf)
} }
void void
splitbill(register struct obj* obj, register struct obj* otmp) splitbill(struct obj *obj, struct obj *otmp)
{ {
/* otmp has been split off from obj */ /* otmp has been split off from obj */
register struct bill_x *bp; struct bill_x *bp;
register long tmp; long tmp;
register struct monst *shkp = shop_keeper(*u.ushops); struct monst *shkp = shop_keeper(*u.ushops);
if (!shkp || !inhishop(shkp)) { if (!shkp || !inhishop(shkp)) {
impossible("splitbill: no resident shopkeeper??"); impossible("splitbill: no resident shopkeeper??");
@@ -3200,7 +3201,9 @@ sellobj_state(int deliberate)
} }
void void
sellobj(register struct obj* obj, coordxy x, coordxy y) sellobj(
struct obj *obj,
coordxy x, coordxy y)
{ {
register struct monst *shkp; register struct monst *shkp;
register struct eshk *eshkp; register struct eshk *eshkp;
@@ -3211,7 +3214,8 @@ sellobj(register struct obj* obj, coordxy x, coordxy y)
if (!*u.ushops) /* do cheapest exclusion test first */ if (!*u.ushops) /* do cheapest exclusion test first */
return; return;
if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp)) shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
if (!shkp || !inhishop(shkp))
return; return;
if (!costly_spot(x, y)) if (!costly_spot(x, y))
return; return;
@@ -3462,9 +3466,6 @@ int
doinvbill( doinvbill(
int mode) /* 0: deliver count 1: paged */ int mode) /* 0: deliver count 1: paged */
{ {
#ifdef __SASC
void sasc_bug(struct obj *, unsigned);
#endif
struct monst *shkp; struct monst *shkp;
struct eshk *eshkp; struct eshk *eshkp;
struct bill_x *bp, *end_bp; struct bill_x *bp, *end_bp;
@@ -3580,11 +3581,14 @@ getprice(register struct obj* obj, boolean shk_buying)
/* shk catches thrown pick-axe */ /* shk catches thrown pick-axe */
struct monst * struct monst *
shkcatch(register struct obj* obj, register coordxy x, register coordxy y) shkcatch(
struct obj *obj,
coordxy x, coordxy y)
{ {
register struct monst *shkp; struct monst *shkp;
if (!(shkp = shop_keeper(inside_shop(x, y))) || !inhishop(shkp)) shkp = shop_keeper(inside_shop(x, y));
if (!shkp || !inhishop(shkp))
return 0; return 0;
if (!helpless(shkp) if (!helpless(shkp)
@@ -4213,7 +4217,7 @@ after_shk_move(struct monst *shkp)
/* for use in levl_follower (mondata.c) */ /* for use in levl_follower (mondata.c) */
boolean boolean
is_fshk(register struct monst* mtmp) is_fshk(struct monst *mtmp)
{ {
return (boolean) (mtmp->isshk && ESHK(mtmp)->following); return (boolean) (mtmp->isshk && ESHK(mtmp)->following);
} }
@@ -4222,13 +4226,19 @@ is_fshk(register struct monst* mtmp)
void void
shopdig(register int fall) shopdig(register int fall)
{ {
register struct monst *shkp = shop_keeper(*u.ushops); struct monst *shkp = shop_keeper(*u.ushops);
int lang; int lang;
const char *grabs = "grabs"; const char *grabs = "grabs";
if (!shkp) if (!shkp)
return; return;
if (!inhishop(shkp)) {
if (Role_if(PM_KNIGHT)) {
You_feel("like a common thief.");
adjalign(-sgn(u.ualign.type));
}
return;
}
/* 0 == can't speak, 1 == makes animal noises, 2 == speaks */ /* 0 == can't speak, 1 == makes animal noises, 2 == speaks */
lang = 0; lang = 0;
if (helpless(shkp) || is_silent(shkp->data)) if (helpless(shkp) || is_silent(shkp->data))
@@ -4238,14 +4248,6 @@ shopdig(register int fall)
else if (shkp->data->msound >= MS_HUMANOID) else if (shkp->data->msound >= MS_HUMANOID)
lang = 2; lang = 2;
if (!inhishop(shkp)) {
if (Role_if(PM_KNIGHT)) {
You_feel("like a common thief.");
adjalign(-sgn(u.ualign.type));
}
return;
}
if (!fall) { if (!fall) {
if (lang == 2) { if (lang == 2) {
if (!Deaf && !muteshk(shkp)) { if (!Deaf && !muteshk(shkp)) {
@@ -4574,30 +4576,36 @@ shop_object(register coordxy x, register coordxy y)
register struct obj *otmp; register struct obj *otmp;
register struct monst *shkp; register struct monst *shkp;
if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp)) shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
if (!shkp || !inhishop(shkp))
return (struct obj *) 0; return (struct obj *) 0;
for (otmp = gl.level.objects[x][y]; otmp; otmp = otmp->nexthere) for (otmp = gl.level.objects[x][y]; otmp; otmp = otmp->nexthere)
if (otmp->oclass != COIN_CLASS) if (otmp->oclass != COIN_CLASS)
break; break;
/* note: otmp might have ->no_charge set, but that's ok */ /* note: otmp might have ->no_charge set, but that's ok */
return (otmp && costly_spot(x, y) return (otmp && costly_spot(x, y) && NOTANGRY(shkp) && !muteshk(shkp))
&& NOTANGRY(shkp) && !muteshk(shkp))
? otmp ? otmp
: (struct obj *) 0; : (struct obj *) 0;
} }
/* give price quotes for all objects linked to this one (ie, on this spot) */ /* give price quotes for all objects linked to this one (ie, on this spot) */
void void
price_quote(register struct obj* first_obj) price_quote(struct obj *first_obj)
{ {
register struct obj *otmp; struct obj *otmp;
char buf[BUFSZ], price[40]; char buf[BUFSZ], price[40];
long cost = 0L; long cost = 0L;
int cnt = 0; int cnt = 0;
boolean contentsonly = FALSE; boolean contentsonly = FALSE;
winid tmpwin; winid tmpwin;
struct monst *shkp = shop_keeper(inside_shop(u.ux, u.uy)); struct monst *shkp;
shkp = shop_keeper(inside_shop(u.ux, u.uy));
/* caller has verified that there is a shopkeeper, but the static
analyzer doesn't realize it */
if (!shkp || !inhishop(shkp))
return;
tmpwin = create_nhwindow(NHW_MENU); tmpwin = create_nhwindow(NHW_MENU);
putstr(tmpwin, 0, "Fine goods for sale:"); putstr(tmpwin, 0, "Fine goods for sale:");
@@ -4869,7 +4877,8 @@ check_unpaid_usage(struct obj* otmp, boolean altusage)
if (!otmp->unpaid || !*u.ushops if (!otmp->unpaid || !*u.ushops
|| (otmp->spe <= 0 && objects[otmp->otyp].oc_charged)) || (otmp->spe <= 0 && objects[otmp->otyp].oc_charged))
return; return;
if (!(shkp = shop_keeper(*u.ushops)) || !inhishop(shkp)) shkp = shop_keeper(*u.ushops);
if (!shkp || !inhishop(shkp))
return; return;
if ((tmp = cost_per_charge(shkp, otmp, altusage)) == 0L) if ((tmp = cost_per_charge(shkp, otmp, altusage)) == 0L)
return; return;
@@ -4908,22 +4917,29 @@ RESTORE_WARNING_FORMAT_NONLITERAL
/* for using charges of unpaid objects "used in the normal manner" */ /* for using charges of unpaid objects "used in the normal manner" */
void void
check_unpaid(struct obj* otmp) check_unpaid(struct obj *otmp)
{ {
check_unpaid_usage(otmp, FALSE); /* normal item use */ check_unpaid_usage(otmp, FALSE); /* normal item use */
} }
void void
costly_gold(coordxy x, coordxy y, long amount, boolean silent) costly_gold(
coordxy x, coordxy y,
long amount,
boolean silent)
{ {
register long delta; long delta;
register struct monst *shkp; struct monst *shkp;
register struct eshk *eshkp; struct eshk *eshkp;
if (!costly_spot(x, y)) if (!costly_spot(x, y))
return; return;
/* shkp now guaranteed to exist by costly_spot() */ /* shkp is guaranteed to exist after successful costly_spot(), but
the static analyzer isn't smart enough to realize that, so follow
the shkp assignment with a redundant test that will always fail */
shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
if (!shkp)
return;
eshkp = ESHK(shkp); eshkp = ESHK(shkp);
if (eshkp->credit >= amount) { if (eshkp->credit >= amount) {
@@ -4965,7 +4981,8 @@ block_door(register coordxy x, register coordxy y)
if (roomno != *u.ushops) if (roomno != *u.ushops)
return FALSE; return FALSE;
if (!(shkp = shop_keeper((char) roomno)) || !inhishop(shkp)) shkp = shop_keeper((char) roomno);
if (!shkp || !inhishop(shkp))
return FALSE; return FALSE;
if (shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y if (shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y
@@ -5000,7 +5017,8 @@ block_entry(register coordxy x, register coordxy y)
roomno = *in_rooms(x, y, SHOPBASE); roomno = *in_rooms(x, y, SHOPBASE);
if (roomno < 0 || !IS_SHOP(roomno)) if (roomno < 0 || !IS_SHOP(roomno))
return FALSE; return FALSE;
if (!(shkp = shop_keeper((char) roomno)) || !inhishop(shkp)) shkp = shop_keeper((char) roomno);
if (!shkp || !inhishop(shkp))
return FALSE; return FALSE;
if (ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy) if (ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy)

View File

@@ -1145,7 +1145,7 @@ dochat(void)
Your("speech is unintelligible underwater."); Your("speech is unintelligible underwater.");
return ECMD_OK; return ECMD_OK;
} }
if (!Deaf && !Blind && (otmp = shop_object(u.ux, u.uy)) != (struct obj *) 0) { if (!Deaf && !Blind && (otmp = shop_object(u.ux, u.uy)) != 0) {
/* standing on something in a shop and chatting causes the shopkeeper /* standing on something in a shop and chatting causes the shopkeeper
to describe the price(s). This can inhibit other chatting inside to describe the price(s). This can inhibit other chatting inside
a shop, but that shouldn't matter much. shop_object() returns an a shop, but that shouldn't matter much. shop_object() returns an