get_adjacent_loc()
use get_adjacent_loc() rather than getdir() directly for some things where you want to ensure valid adjacent coordinates are returned <email deleted> wrote: >>> [...] >>> I've noticed that the loot adjacent spot code doesn't have any >>> isok(x,y) test, so will risk crashing if used at the edge of >>> the screen (whether deliberately, or accidentally due to being >>> confused or stunned when picking the direction). >> Would this not be a problem elsewhere, such as use_leash() too? > Yes, that looks like the same risk. getdir() doesn't validate > that the <u.ux+u.dx, u.uy,u.dy> is safe and neither does m_at(), > so their callers need to. > > I did manage to provoke a crash with #loot on the plane of earth, > although an accidental case would be a lot less likely to happen.
This commit is contained in:
11
src/apply.c
11
src/apply.c
@@ -400,7 +400,7 @@ STATIC_OVL void
|
||||
use_leash(obj)
|
||||
struct obj *obj;
|
||||
{
|
||||
register int x, y;
|
||||
coord cc;
|
||||
register struct monst *mtmp;
|
||||
int spotmon;
|
||||
|
||||
@@ -409,12 +409,9 @@ struct obj *obj;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!getdir((char *)0)) return;
|
||||
if(!get_adjacent_loc((char *)0, (char *)0, u.ux, u.uy, &cc)) return;
|
||||
|
||||
x = u.ux + u.dx;
|
||||
y = u.uy + u.dy;
|
||||
|
||||
if((x == u.ux) && (y == u.uy)) {
|
||||
if((cc.x == u.ux) && (cc.y == u.uy)) {
|
||||
#ifdef STEED
|
||||
if (u.usteed && u.dz > 0) {
|
||||
mtmp = u.usteed;
|
||||
@@ -426,7 +423,7 @@ struct obj *obj;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(mtmp = m_at(x, y))) {
|
||||
if(!(mtmp = m_at(cc.x, cc.y))) {
|
||||
There("is no creature there.");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user