From 8fab53967bc16e2b81f44ac380b90be5e6f5913d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 24 Mar 2017 10:42:00 +0100 Subject: vis-lua: adjust return value validation of called lua functions While the invoked Lua functions are executed in protected mode, the validation of the return values currently happens in unprotected mode. Thus an invaid return value triggers a lua error and because we currently do not have a global panic handler registered this will terminate the editor process. This commit changes the return value validation to silently fall back to default values instead of raising errors. If we want to provide user friendly stack traces showing the origin of the offending value we would have to move the validation into the Lua code. --- vis-lua.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'vis-lua.c') diff --git a/vis-lua.c b/vis-lua.c index eae98b4..6ec6973 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -479,6 +479,10 @@ static int newindex_common(lua_State *L) { return 0; } +static size_t getpos(lua_State *L, int narg) { + return lua_tounsigned(L, narg); +} + static size_t checkpos(lua_State *L, int narg) { lua_Number n = luaL_checknumber(L, narg); if (n >= 0 && n <= SIZE_MAX && n == (size_t)n) @@ -911,7 +915,7 @@ static size_t motion_lua(Vis *vis, Win *win, void *data, size_t pos) { lua_pushunsigned(L, pos); if (pcall(vis, L, 2, 1) != 0) return EPOS; - return checkpos(L, -1); + return getpos(L, -1); } /*** @@ -965,7 +969,7 @@ static size_t operator_lua(Vis *vis, Text *text, OperatorContext *c) { pushpos(L, c->pos); if (pcall(vis, L, 3, 1) != 0) return EPOS; - return checkpos(L, -1); + return getpos(L, -1); } /*** @@ -1017,7 +1021,7 @@ static Filerange textobject_lua(Vis *vis, Win *win, void *data, size_t pos) { lua_pushunsigned(L, pos); if (pcall(vis, L, 2, 2) != 0 || lua_isnil(L, -1)) return text_range_empty(); - return text_range_new(checkpos(L, -2), checkpos(L, -1)); + return text_range_new(getpos(L, -2), getpos(L, -1)); } /*** -- cgit v1.2.3