comparison src/if_lua.c @ 14329:fe651f98e173 v8.1.0180

patch 8.1.0180: static analysis errors in Lua interface commit https://github.com/vim/vim/commit/d6ef5f9b3d3df2d5dcc666c8741e99fcc77043f6 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 13 22:08:23 2018 +0200 patch 8.1.0180: static analysis errors in Lua interface Problem: Static analysis errors in Lua interface. (Coverity) Solution: Check for NULL pointers.
author Christian Brabandt <cb@256bit.org>
date Fri, 13 Jul 2018 22:15:05 +0200
parents 396b71b242b2
children d59bf91128ea
comparison
equal deleted inserted replaced
14328:05295e8ace8d 14329:fe651f98e173
956 char_u *key = (char_u *) luaL_checkstring(L, 2); 956 char_u *key = (char_u *) luaL_checkstring(L, 2);
957 dictitem_T *di; 957 dictitem_T *di;
958 typval_T v; 958 typval_T v;
959 if (d->dv_lock) 959 if (d->dv_lock)
960 luaL_error(L, "dict is locked"); 960 luaL_error(L, "dict is locked");
961 if (key != NULL && *key == NUL) 961 if (key == NULL)
962 return 0;
963 if (*key == NUL)
962 luaL_error(L, "empty key"); 964 luaL_error(L, "empty key");
963 if (!lua_isnil(L, 3)) { /* read value? */ 965 if (!lua_isnil(L, 3)) { /* read value? */
964 luaV_checktypval(L, 3, &v, "setting dict item"); 966 luaV_checktypval(L, 3, &v, "setting dict item");
965 if (d->dv_scope == VAR_DEF_SCOPE && v.v_type == VAR_FUNC) 967 if (d->dv_scope == VAR_DEF_SCOPE && v.v_type == VAR_FUNC)
966 luaL_error(L, "cannot assign funcref to builtin scope"); 968 luaL_error(L, "cannot assign funcref to builtin scope");
967 } 969 }
968 di = dict_find(d, key, -1); 970 di = dict_find(d, key, -1);
969 if (di == NULL) /* non-existing key? */ 971 if (di == NULL) /* non-existing key? */
970 { 972 {
971 if (lua_isnil(L, 3)) return 0; 973 if (lua_isnil(L, 3))
974 return 0;
972 di = dictitem_alloc(key); 975 di = dictitem_alloc(key);
973 if (di == NULL) return 0; 976 if (di == NULL)
977 return 0;
974 if (dict_add(d, di) == FAIL) 978 if (dict_add(d, di) == FAIL)
975 { 979 {
976 vim_free(di); 980 vim_free(di);
977 return 0; 981 return 0;
978 } 982 }
979 } 983 }
980 else 984 else
981 clear_tv(&di->di_tv); 985 clear_tv(&di->di_tv);
982 if (lua_isnil(L, 3)) /* remove? */ 986 if (lua_isnil(L, 3)) /* remove? */
1064 int status; 1068 int status;
1065 typval_T v, rettv; 1069 typval_T v, rettv;
1066 1070
1067 f->args.vval.v_list = list_alloc(); 1071 f->args.vval.v_list = list_alloc();
1068 rettv.v_type = VAR_UNKNOWN; /* as in clear_tv */ 1072 rettv.v_type = VAR_UNKNOWN; /* as in clear_tv */
1069 for (i = 0; i < n; i++) { 1073 if (f->args.vval.v_list == NULL)
1070 luaV_checktypval(L, i + 2, &v, "calling funcref"); 1074 status = FAIL;
1071 list_append_tv(f->args.vval.v_list, &v); 1075 else
1072 } 1076 {
1073 status = func_call(f->tv.vval.v_string, &f->args, NULL, f->self, &rettv); 1077 for (i = 0; i < n; i++) {
1074 if (status == OK) 1078 luaV_checktypval(L, i + 2, &v, "calling funcref");
1075 luaV_pushtypval(L, &rettv); 1079 list_append_tv(f->args.vval.v_list, &v);
1076 clear_tv(&f->args); 1080 }
1077 clear_tv(&rettv); 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);
1087 }
1078 if (status != OK) 1088 if (status != OK)
1079 luaL_error(L, "cannot call funcref"); 1089 luaL_error(L, "cannot call funcref");
1080 return 1; 1090 return 1;
1081 } 1091 }
1082 1092
1558 while (lua_next(L, 1)) 1568 while (lua_next(L, 1))
1559 { 1569 {
1560 char_u *key; 1570 char_u *key;
1561 dictitem_T *di; 1571 dictitem_T *di;
1562 typval_T v; 1572 typval_T v;
1573
1563 lua_pushvalue(L, -2); /* dup key in case it's a number */ 1574 lua_pushvalue(L, -2); /* dup key in case it's a number */
1564 key = (char_u *) lua_tostring(L, -1); 1575 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)
1566 luaL_error(L, "table has empty key"); 1582 luaL_error(L, "table has empty key");
1567 luaV_checktypval(L, -2, &v, "vim.dict"); /* value */ 1583 luaV_checktypval(L, -2, &v, "vim.dict"); /* value */
1568 di = dictitem_alloc(key); 1584 di = dictitem_alloc(key);
1569 if (di == NULL || dict_add(d, di) == FAIL) { 1585 if (di == NULL || dict_add(d, di) == FAIL)
1586 {
1570 vim_free(di); 1587 vim_free(di);
1571 lua_pushnil(L); 1588 lua_pushnil(L);
1572 return 1; 1589 return 1;
1573 } 1590 }
1574 copy_tv(&v, &di->di_tv); 1591 copy_tv(&v, &di->di_tv);