Skip to content

Commit d6ef5f9

Browse files
committed
patch 8.1.0180: static analysis errors in Lua interface
Problem: Static analysis errors in Lua interface. (Coverity) Solution: Check for NULL pointers.
1 parent efc8133 commit d6ef5f9

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

src/if_lua.c

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,9 @@ luaV_dict_newindex(lua_State *L)
958958
typval_T v;
959959
if (d->dv_lock)
960960
luaL_error(L, "dict is locked");
961-
if (key != NULL && *key == NUL)
961+
if (key == NULL)
962+
return 0;
963+
if (*key == NUL)
962964
luaL_error(L, "empty key");
963965
if (!lua_isnil(L, 3)) { /* read value? */
964966
luaV_checktypval(L, 3, &v, "setting dict item");
@@ -968,13 +970,15 @@ luaV_dict_newindex(lua_State *L)
968970
di = dict_find(d, key, -1);
969971
if (di == NULL) /* non-existing key? */
970972
{
971-
if (lua_isnil(L, 3)) return 0;
973+
if (lua_isnil(L, 3))
974+
return 0;
972975
di = dictitem_alloc(key);
973-
if (di == NULL) return 0;
976+
if (di == NULL)
977+
return 0;
974978
if (dict_add(d, di) == FAIL)
975979
{
976-
vim_free(di);
977-
return 0;
980+
vim_free(di);
981+
return 0;
978982
}
979983
}
980984
else
@@ -1066,15 +1070,21 @@ luaV_funcref_call(lua_State *L)
10661070

10671071
f->args.vval.v_list = list_alloc();
10681072
rettv.v_type = VAR_UNKNOWN; /* as in clear_tv */
1069-
for (i = 0; i < n; i++) {
1070-
luaV_checktypval(L, i + 2, &v, "calling funcref");
1071-
list_append_tv(f->args.vval.v_list, &v);
1073+
if (f->args.vval.v_list == NULL)
1074+
status = FAIL;
1075+
else
1076+
{
1077+
for (i = 0; i < n; i++) {
1078+
luaV_checktypval(L, i + 2, &v, "calling funcref");
1079+
list_append_tv(f->args.vval.v_list, &v);
1080+
}
1081+
status = func_call(f->tv.vval.v_string, &f->args,
1082+
NULL, f->self, &rettv);
1083+
if (status == OK)
1084+
luaV_pushtypval(L, &rettv);
1085+
clear_tv(&f->args);
1086+
clear_tv(&rettv);
10721087
}
1073-
status = func_call(f->tv.vval.v_string, &f->args, NULL, f->self, &rettv);
1074-
if (status == OK)
1075-
luaV_pushtypval(L, &rettv);
1076-
clear_tv(&f->args);
1077-
clear_tv(&rettv);
10781088
if (status != OK)
10791089
luaL_error(L, "cannot call funcref");
10801090
return 1;
@@ -1560,13 +1570,20 @@ luaV_dict(lua_State *L)
15601570
char_u *key;
15611571
dictitem_T *di;
15621572
typval_T v;
1573+
15631574
lua_pushvalue(L, -2); /* dup key in case it's a number */
15641575
key = (char_u *) lua_tostring(L, -1);
1565-
if (key != NULL && *key == NUL)
1576+
if (key == NULL)
1577+
{
1578+
lua_pushnil(L);
1579+
return 1;
1580+
}
1581+
if (*key == NUL)
15661582
luaL_error(L, "table has empty key");
15671583
luaV_checktypval(L, -2, &v, "vim.dict"); /* value */
15681584
di = dictitem_alloc(key);
1569-
if (di == NULL || dict_add(d, di) == FAIL) {
1585+
if (di == NULL || dict_add(d, di) == FAIL)
1586+
{
15701587
vim_free(di);
15711588
lua_pushnil(L);
15721589
return 1;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ static char *(features[]) =
789789

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
180,
792794
/**/
793795
179,
794796
/**/

0 commit comments

Comments
 (0)