Finally bothered to add in a method to obtain sector.lines' size internally to prevent going out of bounds.

Admittedly I knew of this particular method from the start but wanted to avoid it in favour of a less-hacky looking method of getting sector.lines' size ...but there was none to be found at all.
This commit is contained in:
Monster Iestyn 2016-01-20 14:56:52 +00:00
parent 3dc0f2b4ff
commit 79e3e2351d

View file

@ -268,7 +268,7 @@ static int sectorlines_get(lua_State *L)
{ {
line_t **seclines = *((line_t ***)luaL_checkudata(L, 1, META_SECTORLINES)); line_t **seclines = *((line_t ***)luaL_checkudata(L, 1, META_SECTORLINES));
size_t i; size_t i;
//size_t numoflines; size_t numoflines = 0;
lua_settop(L, 2); lua_settop(L, 2);
if (!lua_isnumber(L, 2)) if (!lua_isnumber(L, 2))
{ {
@ -286,21 +286,22 @@ static int sectorlines_get(lua_State *L)
} }
} }
/* \TODO: figure out how to find size of seclines array, rather than the size of a pointer! // check first linedef to figure which of its sectors owns this sector->lines pointer
Testing for sectors[0].lines in GFZ1 with a test Lua script: // then check that sector's linecount to get a maximum index
sizeof(seclines) returns 4 //if (!seclines[0])
sizeof(*seclines) returns 4 //return luaL_error(L, "no lines found!"); // no first linedef?????
sizeof(**seclines) returns 84, presumably the size of line_t if (seclines[0]->frontsector->lines == seclines)
You can probably see why I haven't been successful yet, hopefully numoflines = seclines[0]->frontsector->linecount;
//CONS_Printf("sizeof(seclines): %d\n", sizeof(seclines)); else if (seclines[0]->backsector && seclines[0]->backsector->lines == seclines) // check backsector exists first
//CONS_Printf("sizeof(seclines[0]): %d\n", sizeof(seclines[0]));*/ numoflines = seclines[0]->backsector->linecount;
//if neither sector has it then ???
/*numoflines = sizeof(seclines) / sizeof(seclines[0]);
if (!numoflines) if (!numoflines)
return luaL_error(L, "no lines found!");*/ return luaL_error(L, "no lines found!");
i = (size_t)lua_tointeger(L, 2); i = (size_t)lua_tointeger(L, 2);
/*if (i > numoflines) if (i >= numoflines)
return 0;*/ return 0;
LUA_PushUserdata(L, seclines[i], META_LINE); LUA_PushUserdata(L, seclines[i], META_LINE);
return 1; return 1;
} }