mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-21 08:51:10 +00:00
Fix numoflines
calculations in sectorlines_* functions by first typecasting seclines (the sector.lines address) to size_t before doing any math on it, then (after the math) typecast the result to size_t * and dereference it.
And yes, this time I tested it to make sure it works :)
This commit is contained in:
parent
130794cc4d
commit
f028bb0219
1 changed files with 2 additions and 2 deletions
|
@ -445,7 +445,7 @@ static int sectorlines_get(lua_State *L)
|
||||||
// get the "linecount" by shifting our retrieved memory address of "lines" to where "linecount" is in the sector_t, then dereferencing the result
|
// get the "linecount" by shifting our retrieved memory address of "lines" to where "linecount" is in the sector_t, then dereferencing the result
|
||||||
// we need this to determine the array's actual size, and therefore also the maximum value allowed as an index
|
// we need this to determine the array's actual size, and therefore also the maximum value allowed as an index
|
||||||
// this only works if seclines is actually a pointer to a sector's lines member in memory, oh boy
|
// this only works if seclines is actually a pointer to a sector's lines member in memory, oh boy
|
||||||
numoflines = (size_t)(*(seclines - (offsetof(sector_t, lines) - offsetof(sector_t, linecount))));
|
numoflines = (size_t)(*(size_t *)(((size_t)seclines) - (offsetof(sector_t, lines) - offsetof(sector_t, linecount))));
|
||||||
|
|
||||||
/* OLD HACK
|
/* OLD HACK
|
||||||
// check first linedef to figure which of its sectors owns this sector->lines pointer
|
// check first linedef to figure which of its sectors owns this sector->lines pointer
|
||||||
|
@ -479,7 +479,7 @@ static int sectorlines_num(lua_State *L)
|
||||||
return luaL_error(L, "accessed sector_t.lines doesn't exist anymore.");
|
return luaL_error(L, "accessed sector_t.lines doesn't exist anymore.");
|
||||||
|
|
||||||
// see comments in the _get function above
|
// see comments in the _get function above
|
||||||
numoflines = (size_t)(*(seclines - (offsetof(sector_t, lines) - offsetof(sector_t, linecount))));
|
numoflines = (size_t)(*(size_t *)(((size_t)seclines) - (offsetof(sector_t, lines) - offsetof(sector_t, linecount))));
|
||||||
lua_pushinteger(L, numoflines);
|
lua_pushinteger(L, numoflines);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue