Skip to content

Commit

Permalink
patch 8.1.0180: static analysis errors in Lua interface
Browse files Browse the repository at this point in the history
Problem:    Static analysis errors in Lua interface. (Coverity)
Solution:   Check for NULL pointers.
  • Loading branch information
brammool committed Jul 13, 2018
1 parent efc8133 commit d6ef5f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/if_lua.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -958,7 +958,9 @@ luaV_dict_newindex(lua_State *L)
typval_T v; typval_T v;
if (d->dv_lock) if (d->dv_lock)
luaL_error(L, "dict is locked"); luaL_error(L, "dict is locked");
if (key != NULL && *key == NUL) if (key == NULL)
return 0;
if (*key == NUL)
luaL_error(L, "empty key"); luaL_error(L, "empty key");
if (!lua_isnil(L, 3)) { /* read value? */ if (!lua_isnil(L, 3)) { /* read value? */
luaV_checktypval(L, 3, &v, "setting dict item"); luaV_checktypval(L, 3, &v, "setting dict item");
Expand All @@ -968,13 +970,15 @@ luaV_dict_newindex(lua_State *L)
di = dict_find(d, key, -1); di = dict_find(d, key, -1);
if (di == NULL) /* non-existing key? */ if (di == NULL) /* non-existing key? */
{ {
if (lua_isnil(L, 3)) return 0; if (lua_isnil(L, 3))
return 0;
di = dictitem_alloc(key); di = dictitem_alloc(key);
if (di == NULL) return 0; if (di == NULL)
return 0;
if (dict_add(d, di) == FAIL) if (dict_add(d, di) == FAIL)
{ {
vim_free(di); vim_free(di);
return 0; return 0;
} }
} }
else else
Expand Down Expand Up @@ -1066,15 +1070,21 @@ luaV_funcref_call(lua_State *L)


f->args.vval.v_list = list_alloc(); f->args.vval.v_list = list_alloc();
rettv.v_type = VAR_UNKNOWN; /* as in clear_tv */ rettv.v_type = VAR_UNKNOWN; /* as in clear_tv */
for (i = 0; i < n; i++) { if (f->args.vval.v_list == NULL)
luaV_checktypval(L, i + 2, &v, "calling funcref"); status = FAIL;
list_append_tv(f->args.vval.v_list, &v); else
{
for (i = 0; i < n; i++) {
luaV_checktypval(L, i + 2, &v, "calling funcref");
list_append_tv(f->args.vval.v_list, &v);
}
status = func_call(f->tv.vval.v_string, &f->args,
NULL, f->self, &rettv);
if (status == OK)
luaV_pushtypval(L, &rettv);
clear_tv(&f->args);
clear_tv(&rettv);
} }
status = func_call(f->tv.vval.v_string, &f->args, NULL, f->self, &rettv);
if (status == OK)
luaV_pushtypval(L, &rettv);
clear_tv(&f->args);
clear_tv(&rettv);
if (status != OK) if (status != OK)
luaL_error(L, "cannot call funcref"); luaL_error(L, "cannot call funcref");
return 1; return 1;
Expand Down Expand Up @@ -1560,13 +1570,20 @@ luaV_dict(lua_State *L)
char_u *key; char_u *key;
dictitem_T *di; dictitem_T *di;
typval_T v; typval_T v;

lua_pushvalue(L, -2); /* dup key in case it's a number */ lua_pushvalue(L, -2); /* dup key in case it's a number */
key = (char_u *) lua_tostring(L, -1); key = (char_u *) lua_tostring(L, -1);
if (key != NULL && *key == NUL) if (key == NULL)
{
lua_pushnil(L);
return 1;
}
if (*key == NUL)
luaL_error(L, "table has empty key"); luaL_error(L, "table has empty key");
luaV_checktypval(L, -2, &v, "vim.dict"); /* value */ luaV_checktypval(L, -2, &v, "vim.dict"); /* value */
di = dictitem_alloc(key); di = dictitem_alloc(key);
if (di == NULL || dict_add(d, di) == FAIL) { if (di == NULL || dict_add(d, di) == FAIL)
{
vim_free(di); vim_free(di);
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ static char *(features[]) =


static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
180,
/**/ /**/
179, 179,
/**/ /**/
Expand Down

0 comments on commit d6ef5f9

Please sign in to comment.