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:
32
src/cmd.c
32
src/cmd.c
@@ -1958,6 +1958,38 @@ char sym;
|
||||
return !u.dz;
|
||||
}
|
||||
|
||||
/*
|
||||
* uses getdir() but unlike getdir() it specifically
|
||||
* produces coordinates using the direction from getdir()
|
||||
* and verifies that those coordinates are ok.
|
||||
*
|
||||
* If the call to getdir() returns 0, Never_mind is displayed.
|
||||
* If the resulting coordinates are not okay, emsg is displayed.
|
||||
*
|
||||
* Returns non-zero if coordinates in cc are valid.
|
||||
*/
|
||||
int get_adjacent_loc(prompt,emsg,x,y,cc)
|
||||
const char *prompt, *emsg;
|
||||
xchar x,y;
|
||||
coord *cc;
|
||||
{
|
||||
xchar new_x, new_y;
|
||||
if (!getdir(prompt)) {
|
||||
pline(Never_mind);
|
||||
return 0;
|
||||
}
|
||||
new_x = x + u.dx;
|
||||
new_y = y + u.dy;
|
||||
if (cc && isok(new_x,new_y)) {
|
||||
cc->x = new_x;
|
||||
cc->y = new_y;
|
||||
} else {
|
||||
if (emsg) pline(emsg);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
getdir(s)
|
||||
const char *s;
|
||||
|
||||
Reference in New Issue
Block a user