init NhRect, before passing to selection_getbounds
selection_getbounds() has a check and early return. Initialization will ensure a known state if that early return were ever taken. This is an alternative approach to pr #1163.
This commit is contained in:
@@ -1150,6 +1150,7 @@ struct const_globals {
|
||||
const struct obj zeroobj; /* used to zero out a struct obj */
|
||||
const struct monst zeromonst; /* used to zero out a struct monst */
|
||||
const anything zeroany; /* used to zero out union any */
|
||||
const NhRect zeroNhRect; /* used to zero out NhRect */
|
||||
};
|
||||
|
||||
extern const struct const_globals cg;
|
||||
|
||||
@@ -957,6 +957,7 @@ const struct const_globals cg = {
|
||||
DUMMY, /* zeroobj */
|
||||
DUMMY, /* zeromonst */
|
||||
DUMMY, /* zeroany */
|
||||
DUMMY, /* zeroNhRect */
|
||||
};
|
||||
|
||||
#define ZERO(x) memset(&x, 0, sizeof(x))
|
||||
|
||||
14
src/nhlsel.c
14
src/nhlsel.c
@@ -203,7 +203,7 @@ l_selection_numpoints(lua_State *L)
|
||||
struct selectionvar *sel = l_selection_check(L, 1);
|
||||
coordxy x, y;
|
||||
int ret = 0;
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
selection_getbounds(sel, &rect);
|
||||
|
||||
@@ -281,7 +281,7 @@ l_selection_and(lua_State *L)
|
||||
struct selectionvar *sela = l_selection_check(L, 1);
|
||||
struct selectionvar *selb = l_selection_check(L, 2);
|
||||
struct selectionvar *selr = l_selection_push_new(L);
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
rect_bounds(sela->bounds, selb->bounds, &rect);
|
||||
|
||||
@@ -304,7 +304,7 @@ l_selection_or(lua_State *L)
|
||||
struct selectionvar *sela = l_selection_check(L, 1);
|
||||
struct selectionvar *selb = l_selection_check(L, 2);
|
||||
struct selectionvar *selr = l_selection_push_new(L);
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
rect_bounds(sela->bounds, selb->bounds, &rect);
|
||||
|
||||
@@ -328,7 +328,7 @@ l_selection_xor(lua_State *L)
|
||||
struct selectionvar *sela = l_selection_check(L, 1);
|
||||
struct selectionvar *selb = l_selection_check(L, 2);
|
||||
struct selectionvar *selr = l_selection_push_new(L);
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
rect_bounds(sela->bounds, selb->bounds, &rect);
|
||||
|
||||
@@ -355,7 +355,7 @@ l_selection_sub(lua_State *L)
|
||||
struct selectionvar *sela = l_selection_check(L, 1);
|
||||
struct selectionvar *selb = l_selection_check(L, 2);
|
||||
struct selectionvar *selr = l_selection_push_new(L);
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
rect_bounds(sela->bounds, selb->bounds, &rect);
|
||||
|
||||
@@ -445,7 +445,7 @@ static int
|
||||
l_selection_getbounds(lua_State *L)
|
||||
{
|
||||
struct selectionvar *sel = l_selection_check(L, 1);
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
selection_getbounds(sel, &rect);
|
||||
lua_settop(L, 0);
|
||||
@@ -904,7 +904,7 @@ l_selection_iterate(lua_State *L)
|
||||
int argc = lua_gettop(L);
|
||||
struct selectionvar *sel = (struct selectionvar *) 0;
|
||||
int x, y;
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
if (argc == 2 && lua_type(L, 2) == LUA_TFUNCTION) {
|
||||
sel = l_selection_check(L, 1);
|
||||
|
||||
14
src/sp_lev.c
14
src/sp_lev.c
@@ -4675,7 +4675,7 @@ struct selectionvar *
|
||||
selection_not(struct selectionvar *s)
|
||||
{
|
||||
int x, y;
|
||||
NhRect tmprect;
|
||||
NhRect tmprect = cg.zeroNhRect;
|
||||
|
||||
for (x = 0; x < s->wid; x++)
|
||||
for (y = 0; y < s->hei; y++)
|
||||
@@ -4689,7 +4689,7 @@ selection_filter_mapchar(struct selectionvar *ov, xint16 typ, int lit)
|
||||
{
|
||||
int x, y;
|
||||
struct selectionvar *ret;
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
if (!ov)
|
||||
return NULL;
|
||||
@@ -4727,7 +4727,7 @@ selection_filter_percent(
|
||||
{
|
||||
int x, y;
|
||||
struct selectionvar *ret;
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
if (!ov)
|
||||
return NULL;
|
||||
@@ -4753,7 +4753,7 @@ selection_rndcoord(
|
||||
int idx = 0;
|
||||
int c;
|
||||
int dx, dy;
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
selection_getbounds(ov, &rect);
|
||||
|
||||
@@ -4794,7 +4794,7 @@ selection_do_grow(struct selectionvar *ov, int dir)
|
||||
{
|
||||
coordxy x, y;
|
||||
struct selectionvar *tmp;
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
if (!ov)
|
||||
return;
|
||||
@@ -5222,7 +5222,7 @@ selection_iterate(
|
||||
genericptr_t arg)
|
||||
{
|
||||
coordxy x, y;
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
if (!ov)
|
||||
return;
|
||||
@@ -5645,7 +5645,7 @@ lspo_replace_terrain(lua_State *L)
|
||||
lua_Integer x1, y1, x2, y2;
|
||||
int chance;
|
||||
int tolit;
|
||||
NhRect rect;
|
||||
NhRect rect = cg.zeroNhRect;
|
||||
|
||||
create_des_coder();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user