diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-01-30 08:09:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-30 08:09:25 +0800 |
commit | 4ffc20c9515294481486e81271a8edeeff203140 (patch) | |
tree | 63e87fd82940bf81a757fee6303a700a6339a3f8 /src/nvim/lua/executor.c | |
parent | a2070ba8773ca264f68a4cfb50cb3d12219838e7 (diff) | |
download | rneovim-4ffc20c9515294481486e81271a8edeeff203140.tar.gz rneovim-4ffc20c9515294481486e81271a8edeeff203140.tar.bz2 rneovim-4ffc20c9515294481486e81271a8edeeff203140.zip |
fix(lua): avoid internal error when :luado deletes lines (#27262)
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 62e82175c3..5d51d58b1d 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1732,10 +1732,15 @@ void ex_luado(exarg_T *const eap) nlua_error(lstate, _("E5110: Error executing lua: %.*s")); return; } + + buf_T *const was_curbuf = curbuf; + for (linenr_T l = eap->line1; l <= eap->line2; l++) { + // Check the line number, the command may have deleted lines. if (l > curbuf->b_ml.ml_line_count) { break; } + lua_pushvalue(lstate, -1); const char *const old_line = ml_get_buf(curbuf, l); // Get length of old_line here as calling Lua code may free it. @@ -1746,6 +1751,13 @@ void ex_luado(exarg_T *const eap) nlua_error(lstate, _("E5111: Error calling lua: %.*s")); break; } + + // Catch the command switching to another buffer. + // Check the line number, the command may have deleted lines. + if (curbuf != was_curbuf || l > curbuf->b_ml.ml_line_count) { + break; + } + if (lua_isstring(lstate, -1)) { size_t new_line_len; const char *const new_line = lua_tolstring(lstate, -1, &new_line_len); @@ -1760,6 +1772,7 @@ void ex_luado(exarg_T *const eap) } lua_pop(lstate, 1); } + lua_pop(lstate, 1); check_cursor(); redraw_curbuf_later(UPD_NOT_VALID); |