new static analyzer fix - nhlua.c
Cope with get_nh_lua_variable() possibly returning Null. Either or both of the DISABLE_WARNING_UNREACHABLE_CODE and RESTORE_WARNING_UNREACHABLE_CODE in the vicinity looked misplaced so I took them out. They may need to be added back in.
This commit is contained in:
23
src/nhlua.c
23
src/nhlua.c
@@ -1030,9 +1030,7 @@ nhl_dnum_name(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DISABLE_WARNING_UNREACHABLE_CODE
|
/* set or get variables which are saved and restored along with the game.
|
||||||
|
|
||||||
/* set or get variables which are saved and restored along the game.
|
|
||||||
nh.variable("test", 10);
|
nh.variable("test", 10);
|
||||||
local ten = nh.variable("test"); */
|
local ten = nh.variable("test"); */
|
||||||
static int
|
static int
|
||||||
@@ -1141,24 +1139,27 @@ get_nh_lua_variables(void)
|
|||||||
void
|
void
|
||||||
save_luadata(NHFILE *nhfp)
|
save_luadata(NHFILE *nhfp)
|
||||||
{
|
{
|
||||||
char *lua_data = get_nh_lua_variables();
|
unsigned lua_data_len;
|
||||||
long lua_data_len = strlen(lua_data) + 1;
|
char *lua_data = get_nh_lua_variables(); /* note: '\0' terminated */
|
||||||
|
|
||||||
bwrite(nhfp->fd, (genericptr_t) &lua_data_len, sizeof lua_data_len);
|
if (!lua_data)
|
||||||
bwrite(nhfp->fd, (genericptr_t) lua_data, strlen(lua_data) + 1);
|
lua_data = emptystr;
|
||||||
|
lua_data_len = Strlen(lua_data) + 1; /* +1: include the terminator */
|
||||||
|
bwrite(nhfp->fd, (genericptr_t) &lua_data_len,
|
||||||
|
(unsigned) sizeof lua_data_len);
|
||||||
|
bwrite(nhfp->fd, (genericptr_t) lua_data, lua_data_len);
|
||||||
free(lua_data);
|
free(lua_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
RESTORE_WARNING_UNREACHABLE_CODE
|
|
||||||
|
|
||||||
/* restore nh_lua_variables table from file */
|
/* restore nh_lua_variables table from file */
|
||||||
void
|
void
|
||||||
restore_luadata(NHFILE *nhfp)
|
restore_luadata(NHFILE *nhfp)
|
||||||
{
|
{
|
||||||
long lua_data_len;
|
unsigned lua_data_len;
|
||||||
char *lua_data;
|
char *lua_data;
|
||||||
|
|
||||||
mread(nhfp->fd, (genericptr_t) &lua_data_len, sizeof lua_data_len);
|
mread(nhfp->fd, (genericptr_t) &lua_data_len,
|
||||||
|
(unsigned) sizeof lua_data_len);
|
||||||
lua_data = (char *) alloc(lua_data_len);
|
lua_data = (char *) alloc(lua_data_len);
|
||||||
mread(nhfp->fd, (genericptr_t) lua_data, lua_data_len);
|
mread(nhfp->fd, (genericptr_t) lua_data, lua_data_len);
|
||||||
if (!gl.luacore)
|
if (!gl.luacore)
|
||||||
|
|||||||
Reference in New Issue
Block a user