From fb3f9699362f8d51c3b48fcaea1eb2ed16c81454 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sun, 11 Aug 2024 20:09:17 +0200 Subject: [PATCH] Problem: crash with WinNewPre autocommand Problem: crash with WinNewPre autocommand, because window structures are not yet safe to use Solution: Don't trigger WinNewPre on :tabnew Signed-off-by: Christian Brabandt --- runtime/doc/autocmd.txt | 8 +++-- src/testdir/crash/nullpointer | Bin 0 -> 315 bytes src/testdir/test_autocmd.vim | 63 ++++++++++++++++++++++++++-------- src/testdir/test_crash.vim | 6 ++++ src/version.c | 2 ++ src/window.c | 7 ++-- 6 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 src/testdir/crash/nullpointer diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 0461c0454e..f6d32db398 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1,4 +1,4 @@ -*autocmd.txt* For Vim version 9.1. Last change: 2024 Jul 17 +*autocmd.txt* For Vim version 9.1. Last change: 2024 Aug 10 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1427,8 +1427,10 @@ WinLeave Before leaving a window. If the window to be *WinNewPre* WinNewPre Before creating a new window. Triggered before commands that modify window layout by - creating a split or new tab page. Not done for - the first window, when Vim has just started. + creating a split. + Not done for creating tabs or for the first + window, as the window structure is not + initialized yet and so is generally not safe. It is not allowed to modify window layout while executing commands for the WinNewPre event. diff --git a/src/testdir/crash/nullpointer b/src/testdir/crash/nullpointer new file mode 100644 index 0000000000000000000000000000000000000000..c8ff3a4832f3c9ff253315c61e9b9bf997c11038 GIT binary patch literal 315 zc-mXYRa9g(nJYCeEu~e*FjbrZ2pnU$?Cov2bhuLaxk?Ng>N88*Wf@fR@{4k%Z3S4> zV-4-??UT54z#@_=Dk_Cmg@uJyK#*8kq5uROJP=YqKtM+T0-Q?If>IMxIJGzx1i;#C z(6q4wH9*xe^5&No_!@vL{lLJLWXJ^sj0}1C$vLTslT|>x{J5BELmfjPFsSW}0fIOn zmQnein3T#@l9tp_localdir = (tp->tp_localdir == NULL) ? NULL : vim_strsave(tp->tp_localdir); - trigger_winnewpre(); - // Create a new empty window. if (win_alloc_firstwin(tp->tp_curwin) == OK) { -- 2.47.2