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:
nhmall
2023-12-13 00:21:32 -05:00
parent dc02eb3e4f
commit 3cfd579d37
4 changed files with 16 additions and 14 deletions
+1
View File
@@ -1150,6 +1150,7 @@ struct const_globals {
const struct obj zeroobj; /* used to zero out a struct obj */ const struct obj zeroobj; /* used to zero out a struct obj */
const struct monst zeromonst; /* used to zero out a struct monst */ const struct monst zeromonst; /* used to zero out a struct monst */
const anything zeroany; /* used to zero out union any */ const anything zeroany; /* used to zero out union any */
const NhRect zeroNhRect; /* used to zero out NhRect */
}; };
extern const struct const_globals cg; extern const struct const_globals cg;
+1
View File
@@ -957,6 +957,7 @@ const struct const_globals cg = {
DUMMY, /* zeroobj */ DUMMY, /* zeroobj */
DUMMY, /* zeromonst */ DUMMY, /* zeromonst */
DUMMY, /* zeroany */ DUMMY, /* zeroany */
DUMMY, /* zeroNhRect */
}; };
#define ZERO(x) memset(&x, 0, sizeof(x)) #define ZERO(x) memset(&x, 0, sizeof(x))
+7 -7
View File
@@ -203,7 +203,7 @@ l_selection_numpoints(lua_State *L)
struct selectionvar *sel = l_selection_check(L, 1); struct selectionvar *sel = l_selection_check(L, 1);
coordxy x, y; coordxy x, y;
int ret = 0; int ret = 0;
NhRect rect; NhRect rect = cg.zeroNhRect;
selection_getbounds(sel, &rect); selection_getbounds(sel, &rect);
@@ -281,7 +281,7 @@ l_selection_and(lua_State *L)
struct selectionvar *sela = l_selection_check(L, 1); struct selectionvar *sela = l_selection_check(L, 1);
struct selectionvar *selb = l_selection_check(L, 2); struct selectionvar *selb = l_selection_check(L, 2);
struct selectionvar *selr = l_selection_push_new(L); struct selectionvar *selr = l_selection_push_new(L);
NhRect rect; NhRect rect = cg.zeroNhRect;
rect_bounds(sela->bounds, selb->bounds, &rect); 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 *sela = l_selection_check(L, 1);
struct selectionvar *selb = l_selection_check(L, 2); struct selectionvar *selb = l_selection_check(L, 2);
struct selectionvar *selr = l_selection_push_new(L); struct selectionvar *selr = l_selection_push_new(L);
NhRect rect; NhRect rect = cg.zeroNhRect;
rect_bounds(sela->bounds, selb->bounds, &rect); 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 *sela = l_selection_check(L, 1);
struct selectionvar *selb = l_selection_check(L, 2); struct selectionvar *selb = l_selection_check(L, 2);
struct selectionvar *selr = l_selection_push_new(L); struct selectionvar *selr = l_selection_push_new(L);
NhRect rect; NhRect rect = cg.zeroNhRect;
rect_bounds(sela->bounds, selb->bounds, &rect); 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 *sela = l_selection_check(L, 1);
struct selectionvar *selb = l_selection_check(L, 2); struct selectionvar *selb = l_selection_check(L, 2);
struct selectionvar *selr = l_selection_push_new(L); struct selectionvar *selr = l_selection_push_new(L);
NhRect rect; NhRect rect = cg.zeroNhRect;
rect_bounds(sela->bounds, selb->bounds, &rect); rect_bounds(sela->bounds, selb->bounds, &rect);
@@ -445,7 +445,7 @@ static int
l_selection_getbounds(lua_State *L) l_selection_getbounds(lua_State *L)
{ {
struct selectionvar *sel = l_selection_check(L, 1); struct selectionvar *sel = l_selection_check(L, 1);
NhRect rect; NhRect rect = cg.zeroNhRect;
selection_getbounds(sel, &rect); selection_getbounds(sel, &rect);
lua_settop(L, 0); lua_settop(L, 0);
@@ -904,7 +904,7 @@ l_selection_iterate(lua_State *L)
int argc = lua_gettop(L); int argc = lua_gettop(L);
struct selectionvar *sel = (struct selectionvar *) 0; struct selectionvar *sel = (struct selectionvar *) 0;
int x, y; int x, y;
NhRect rect; NhRect rect = cg.zeroNhRect;
if (argc == 2 && lua_type(L, 2) == LUA_TFUNCTION) { if (argc == 2 && lua_type(L, 2) == LUA_TFUNCTION) {
sel = l_selection_check(L, 1); sel = l_selection_check(L, 1);
+7 -7
View File
@@ -4675,7 +4675,7 @@ struct selectionvar *
selection_not(struct selectionvar *s) selection_not(struct selectionvar *s)
{ {
int x, y; int x, y;
NhRect tmprect; NhRect tmprect = cg.zeroNhRect;
for (x = 0; x < s->wid; x++) for (x = 0; x < s->wid; x++)
for (y = 0; y < s->hei; y++) for (y = 0; y < s->hei; y++)
@@ -4689,7 +4689,7 @@ selection_filter_mapchar(struct selectionvar *ov, xint16 typ, int lit)
{ {
int x, y; int x, y;
struct selectionvar *ret; struct selectionvar *ret;
NhRect rect; NhRect rect = cg.zeroNhRect;
if (!ov) if (!ov)
return NULL; return NULL;
@@ -4727,7 +4727,7 @@ selection_filter_percent(
{ {
int x, y; int x, y;
struct selectionvar *ret; struct selectionvar *ret;
NhRect rect; NhRect rect = cg.zeroNhRect;
if (!ov) if (!ov)
return NULL; return NULL;
@@ -4753,7 +4753,7 @@ selection_rndcoord(
int idx = 0; int idx = 0;
int c; int c;
int dx, dy; int dx, dy;
NhRect rect; NhRect rect = cg.zeroNhRect;
selection_getbounds(ov, &rect); selection_getbounds(ov, &rect);
@@ -4794,7 +4794,7 @@ selection_do_grow(struct selectionvar *ov, int dir)
{ {
coordxy x, y; coordxy x, y;
struct selectionvar *tmp; struct selectionvar *tmp;
NhRect rect; NhRect rect = cg.zeroNhRect;
if (!ov) if (!ov)
return; return;
@@ -5222,7 +5222,7 @@ selection_iterate(
genericptr_t arg) genericptr_t arg)
{ {
coordxy x, y; coordxy x, y;
NhRect rect; NhRect rect = cg.zeroNhRect;
if (!ov) if (!ov)
return; return;
@@ -5645,7 +5645,7 @@ lspo_replace_terrain(lua_State *L)
lua_Integer x1, y1, x2, y2; lua_Integer x1, y1, x2, y2;
int chance; int chance;
int tolit; int tolit;
NhRect rect; NhRect rect = cg.zeroNhRect;
create_des_coder(); create_des_coder();