mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-25 05:41:42 +00:00
Merge branch '1168-accessing-an-invalid-variable-in-ticcmd_t-crashes-the-game' into 'next'
check if LUA field exists before accessing it Closes #1168 See merge request STJr/SRB2!2261
This commit is contained in:
commit
ae8bfbe763
4 changed files with 41 additions and 9 deletions
|
@ -31,6 +31,26 @@ LUALIB_API void (luaL_setn) (lua_State *L, int t, int n);
|
|||
/* extra error code for `luaL_load' */
|
||||
#define LUA_ERRFILE (LUA_ERRERR+1)
|
||||
|
||||
/* Compiler-specific attributes and other macros */
|
||||
|
||||
#ifdef __GNUC__ // __attribute__ ((X))
|
||||
|
||||
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && defined (__MINGW32__) // MinGW, >= GCC 4.1
|
||||
#if 0 //defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO > 0
|
||||
#define FUNCREPORT __attribute__ ((format(gnu_printf, 2, 3)))
|
||||
#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) // >= GCC 4.4
|
||||
#define FUNCREPORT __attribute__ ((format(ms_printf, 2, 3)))
|
||||
#else
|
||||
#define FUNCREPORT __attribute__ ((format(printf, 2, 3)))
|
||||
#endif
|
||||
#else
|
||||
#define FUNCREPORT __attribute__ ((format(printf, 2, 3)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef FUNCREPORT
|
||||
#define FUNCREPORT
|
||||
#endif
|
||||
|
||||
typedef struct luaL_Reg {
|
||||
const char *name;
|
||||
|
@ -65,7 +85,7 @@ LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
|
|||
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
|
||||
|
||||
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
|
||||
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
|
||||
LUALIB_API FUNCREPORT int (luaL_error) (lua_State *L, const char *fmt, ...);
|
||||
|
||||
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
|
||||
const char *const lst[]);
|
||||
|
|
|
@ -483,7 +483,7 @@ static int spriteinfo_set(lua_State *L)
|
|||
}
|
||||
}
|
||||
else
|
||||
return luaL_error(L, va("Field %s does not exist in spriteinfo_t", field));
|
||||
return luaL_error(L, "Field %s does not exist in spriteinfo_t", field);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -577,7 +577,7 @@ static int framepivot_get(lua_State *L)
|
|||
lua_pushinteger(L, 0);
|
||||
}
|
||||
else
|
||||
return luaL_error(L, va("Field %s does not exist in spriteframepivot_t", field));
|
||||
return luaL_error(L, "Field %s does not exist in spriteframepivot_t", field);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -604,7 +604,7 @@ static int framepivot_set(lua_State *L)
|
|||
else if (fastcmp("rotaxis", field))
|
||||
LUA_UsageWarning(L, "\"rotaxis\" is deprecated and will be removed.")
|
||||
else
|
||||
return luaL_error(L, va("Field %s does not exist in spriteframepivot_t", field));
|
||||
return luaL_error(L, "Field %s does not exist in spriteframepivot_t", field);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1663,7 +1663,7 @@ static void setRamp(lua_State *L, skincolor_t* c) {
|
|||
lua_pushnil(L);
|
||||
for (i=0; i<COLORRAMPSIZE; i++) {
|
||||
if (lua_objlen(L,-2)!=COLORRAMPSIZE) {
|
||||
luaL_error(L, LUA_QL("skincolor_t") " field 'ramp' must be %d entries long; got %d.", COLORRAMPSIZE, lua_objlen(L,-2));
|
||||
luaL_error(L, LUA_QL("skincolor_t") " field 'ramp' must be %d entries long; got %d.", COLORRAMPSIZE, luaL_getn(L,-2));
|
||||
break;
|
||||
}
|
||||
if (lua_next(L, -2) != 0) {
|
||||
|
|
|
@ -1003,6 +1003,9 @@ static int mapthing_get(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (field == (enum mapthing_e)-1)
|
||||
return LUA_ErrInvalid(L, "fields");
|
||||
|
||||
switch (field)
|
||||
{
|
||||
case mapthing_valid:
|
||||
|
@ -1061,7 +1064,7 @@ static int mapthing_get(lua_State *L)
|
|||
break;
|
||||
default:
|
||||
if (devparm)
|
||||
return luaL_error(L, LUA_QL("mapthing_t") " has no field named " LUA_QS, field);
|
||||
return luaL_error(L, "%s %s", LUA_QL("mapthing_t"), va("has no field named: %ui", field));
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
@ -1078,6 +1081,9 @@ static int mapthing_set(lua_State *L)
|
|||
if (!mt)
|
||||
return luaL_error(L, "accessed mapthing_t doesn't exist anymore.");
|
||||
|
||||
if (field == (enum mapthing_e)-1)
|
||||
return LUA_ErrInvalid(L, "fields");
|
||||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter mapthing_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
|
@ -1135,7 +1141,7 @@ static int mapthing_set(lua_State *L)
|
|||
mt->mobj = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
||||
break;
|
||||
default:
|
||||
return luaL_error(L, LUA_QL("mapthing_t") " has no field named " LUA_QS, field);
|
||||
return luaL_error(L, "%s %s", LUA_QL("mapthing_t"), va("has no field named: %ui", field));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1423,8 +1423,8 @@ static int power_len(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#define NOFIELD luaL_error(L, LUA_QL("ticcmd_t") " has no field named " LUA_QS, field)
|
||||
#define NOSET luaL_error(L, LUA_QL("ticcmd_t") " field " LUA_QS " should not be set directly.", ticcmd_opt[field])
|
||||
#define NOFIELD luaL_error(L, "%s %s", LUA_QL("ticcmd_t"), va("has no field named %ui", field))
|
||||
#define NOSET luaL_error(L, LUA_QL("ticcmd_t") " field %s should not be set directly.", ticcmd_opt[field])
|
||||
|
||||
enum ticcmd_e
|
||||
{
|
||||
|
@ -1455,6 +1455,9 @@ static int ticcmd_get(lua_State *L)
|
|||
if (!cmd)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
|
||||
if (field == (enum ticcmd_e)-1)
|
||||
return LUA_ErrInvalid(L, "fields");
|
||||
|
||||
switch (field)
|
||||
{
|
||||
case ticcmd_forwardmove:
|
||||
|
@ -1489,6 +1492,9 @@ static int ticcmd_set(lua_State *L)
|
|||
if (!cmd)
|
||||
return LUA_ErrInvalid(L, "ticcmd_t");
|
||||
|
||||
if (field == (enum ticcmd_e)-1)
|
||||
return LUA_ErrInvalid(L, "fields");
|
||||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
||||
|
||||
|
|
Loading…
Reference in a new issue