diff options
| author | skewb1k <skewb1kunix@gmail.com> | 2025-12-09 21:59:06 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-09 13:59:06 -0500 |
| commit | bc0635a9fc9c15a2423d4eb35f627d127d00fa46 (patch) | |
| tree | 126aa84b6cc9d63f6269533dc6cf84bb07b69e31 /src/nvim/lua/executor.c | |
| parent | 3b6e8e484edfb5f60990def1d90c4d046b59dc7e (diff) | |
| download | rneovim-bc0635a9fc9c15a2423d4eb35f627d127d00fa46.tar.gz rneovim-bc0635a9fc9c15a2423d4eb35f627d127d00fa46.tar.bz2 rneovim-bc0635a9fc9c15a2423d4eb35f627d127d00fa46.zip | |
fix(lua): vim.wait(math.huge) fails #36885
Problem:
`nlua_wait()` uses `luaL_checkinteger()` which doesn't support
`math.huge` since it's double type. On PUC Lua this fails with
'number has no integer representation' error and on LuaJIT this
overflows int.
Solution:
Use `luaL_checknumber()` and handle `math.huge`.
Diffstat (limited to 'src/nvim/lua/executor.c')
| -rw-r--r-- | src/nvim/lua/executor.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 124fce58b6..30d3f26f0e 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -3,6 +3,7 @@ #include <lauxlib.h> #include <lua.h> #include <lualib.h> +#include <math.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> @@ -451,10 +452,19 @@ static int nlua_wait(lua_State *lstate) return luaL_error(lstate, e_fast_api_disabled, "vim.wait"); } - intptr_t timeout = luaL_checkinteger(lstate, 1); - if (timeout < 0) { + double timeout_number = luaL_checknumber(lstate, 1); + if (timeout_number < 0) { return luaL_error(lstate, "timeout must be >= 0"); } + int64_t timeout; + if (isinf(timeout_number) || timeout_number > (double)INT64_MAX) { + timeout = INT64_MAX; + } else { + if (isnan(timeout_number) || timeout_number != trunc(timeout_number)) { + return luaL_error(lstate, "timeout has no integer representation"); + } + timeout = (int64_t)timeout_number; + } int lua_top = lua_gettop(lstate); @@ -510,7 +520,7 @@ static int nlua_wait(lua_State *lstate) LOOP_PROCESS_EVENTS_UNTIL(&main_loop, loop_events, - (int)timeout, + timeout, got_int || (is_function ? nlua_wait_condition(lstate, &pcall_status, &callback_result, |