aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/stdlib.c
diff options
context:
space:
mode:
authorJaehwang Jung <tomtomjhj@gmail.com>2024-04-22 23:46:43 +0900
committerLewis Russell <me@lewisr.dev>2024-05-07 14:36:55 +0100
commit4caf71af58f34726bf6f1d8a2d5ddeaf650e6286 (patch)
tree00aed84ae031672960a78f330375b330dd48d6d6 /src/nvim/lua/stdlib.c
parent93940af1d456ec52f39cb2912b5ffb8445d26c98 (diff)
downloadrneovim-4caf71af58f34726bf6f1d8a2d5ddeaf650e6286.tar.gz
rneovim-4caf71af58f34726bf6f1d8a2d5ddeaf650e6286.tar.bz2
rneovim-4caf71af58f34726bf6f1d8a2d5ddeaf650e6286.zip
refactor(fold): avoid coverity false-positive
Also add some more argument checks.
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r--src/nvim/lua/stdlib.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index 032cb246bf..22ee0a1c98 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -549,19 +549,21 @@ static int nlua_iconv(lua_State *lstate)
static int nlua_foldupdate(lua_State *lstate)
{
handle_T window = (handle_T)luaL_checkinteger(lstate, 1);
- Error err = ERROR_INIT;
- win_T *win = find_window_by_handle(window, &err);
- if (ERROR_SET(&err)) {
- nlua_push_errstr(lstate, err.msg);
- api_clear_error(&err);
- lua_error(lstate);
- return 0;
+ win_T *win = handle_get_window(window);
+ if (!win) {
+ return luaL_error(lstate, "invalid window");
+ }
+ // input is zero-based end-exclusive range
+ linenr_T top = (linenr_T)luaL_checkinteger(lstate, 2) + 1;
+ if (top < 1 || top > win->w_buffer->b_ml.ml_line_count) {
+ return luaL_error(lstate, "invalid top");
+ }
+ linenr_T bot = (linenr_T)luaL_checkinteger(lstate, 3);
+ if (top > bot) {
+ return luaL_error(lstate, "invalid bot");
}
- linenr_T start = (linenr_T)luaL_checkinteger(lstate, 2);
- linenr_T end = (linenr_T)luaL_checkinteger(lstate, 3);
-
- foldUpdate(win, start + 1, end);
+ foldUpdate(win, top, bot);
return 0;
}