diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-03-24 10:42:00 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-03-24 10:52:40 +0100 |
| commit | 8fab53967bc16e2b81f44ac380b90be5e6f5913d (patch) | |
| tree | da83e24dff9becf6b3a8bdc9995e4be7ea1c6961 | |
| parent | 865848dda55600dbdeb2424763dbf753c7e1f0e5 (diff) | |
| download | vis-8fab53967bc16e2b81f44ac380b90be5e6f5913d.tar.gz vis-8fab53967bc16e2b81f44ac380b90be5e6f5913d.tar.xz | |
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.
| -rw-r--r-- | vis-lua.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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)); } /*** |
