From 6f98371532fcff911b462d51bc64f2ce8a6ae682 Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Fri, 24 Dec 2021 18:11:27 +0000
Subject: [PATCH] patch 8.2.3884: crash when clearing the argument list while
 using it
Conflict:NA
Reference:https://github.com/vim/vim/commit/6f98371532fcff911b462d51bc64f2ce8a6ae682

Problem:    Crash when clearing the argument list while using it.
Solution:   Lock the argument list for ":all".
---
 src/arglist.c                | 3 +++
 src/testdir/test_arglist.vim | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/src/arglist.c b/src/arglist.c
index 21c38c1..cdd70ca 100644
--- a/src/arglist.c
+++ b/src/arglist.c
@@ -902,6 +902,7 @@ do_arg_all(
     tabpage_T	*old_curtab, *last_curtab;
     win_T	*new_curwin = NULL;
     tabpage_T	*new_curtab = NULL;
+    int		prev_arglist_locked = arglist_locked;
 
     if (ARGCOUNT <= 0)
     {
@@ -921,6 +922,7 @@ do_arg_all(
     // watch out for its size to be changed.
     alist = curwin->w_alist;
     ++alist->al_refcount;
+    arglist_locked = TRUE;
 
     old_curwin = curwin;
     old_curtab = curtab;
@@ -1132,6 +1134,7 @@ do_arg_all(
 
     // Remove the "lock" on the argument list.
     alist_unlink(alist);
+    arglist_locked = prev_arglist_locked;
 
     --autocmd_no_enter;
 
diff --git a/src/testdir/test_arglist.vim b/src/testdir/test_arglist.vim
index c486b18..1c94fe9 100644
--- a/src/testdir/test_arglist.vim
+++ b/src/testdir/test_arglist.vim
@@ -505,3 +505,10 @@ func Test_argdo()
   call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l)
   bwipe Xa.c Xb.c Xc.c
 endfunc
+
+func Test_clear_arglist_in_all()
+  n 0 00 000 0000 00000 000000
+  au! * 0 n 0
+  all
+  au! *
+endfunc
-- 
2.27.0

