aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-12-07 11:36:34 +0800
committerGitHub <noreply@github.com>2022-12-07 11:36:34 +0800
commited23cd3e50e778604e45e85bc939271a7759ca1f (patch)
tree41409a2e8d4d8971727af43495aa00a1ce75d236
parenteab71e7875782144ca6c62269fc6f333bc061001 (diff)
downloadrneovim-ed23cd3e50e778604e45e85bc939271a7759ca1f.tar.gz
rneovim-ed23cd3e50e778604e45e85bc939271a7759ca1f.tar.bz2
rneovim-ed23cd3e50e778604e45e85bc939271a7759ca1f.zip
fix(float): fix crash with bufpos and non-existent window (#21319)
-rw-r--r--src/nvim/window.c16
-rw-r--r--test/functional/ui/float_spec.lua9
2 files changed, 17 insertions, 8 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 86c936c734..1216bd8dcc 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -843,16 +843,16 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
grid_adjust(&grid, &row_off, &col_off);
row += row_off;
col += col_off;
+ if (wp->w_float_config.bufpos.lnum >= 0) {
+ pos_T pos = { wp->w_float_config.bufpos.lnum + 1,
+ wp->w_float_config.bufpos.col, 0 };
+ int trow, tcol, tcolc, tcole;
+ textpos2screenpos(parent, &pos, &trow, &tcol, &tcolc, &tcole, true);
+ row += trow - 1;
+ col += tcol - 1;
+ }
}
api_clear_error(&dummy);
- if (wp->w_float_config.bufpos.lnum >= 0) {
- pos_T pos = { wp->w_float_config.bufpos.lnum + 1,
- wp->w_float_config.bufpos.col, 0 };
- int trow, tcol, tcolc, tcole;
- textpos2screenpos(parent, &pos, &trow, &tcol, &tcolc, &tcole, true);
- row += trow - 1;
- col += tcol - 1;
- }
wp->w_winrow = row;
wp->w_wincol = col;
} else {
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua
index dbf31ad753..bb09cfd504 100644
--- a/test/functional/ui/float_spec.lua
+++ b/test/functional/ui/float_spec.lua
@@ -391,6 +391,15 @@ describe('float window', function()
eq(winids, eval('winids'))
end)
+ it('no crash with bufpos and non-existent window', function()
+ command('new')
+ local closed_win = meths.get_current_win().id
+ command('close')
+ local buf = meths.create_buf(false,false)
+ meths.open_win(buf, true, {relative='win', win=closed_win, width=1, height=1, bufpos={0,0}})
+ assert_alive()
+ end)
+
it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function()
local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local float_win = meths.open_win(0, true, float_opts)