From dff3c9c1a789351a741b6a430862c8b2a0eff383 Mon Sep 17 00:00:00 2001
From: 826814741_6 <44406129+826814741-6@users.noreply.github.com>
Date: Tue, 10 Dec 2024 17:15:14 +0100
Subject: [PATCH] patch 9.1.0918: tiny Vim crashes with fuzzy buffer completion

Problem:  tiny Vim crashes with fuzzy buffer completion
Solution: Adjust #ifdefs in ExpandBufnames() (826814741_6)

closes: #16200

Signed-off-by: h-east <h.east.727@gmail.com>
Signed-off-by: 826814741_6 <44406129+826814741-6@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
---
 src/buffer.c             |  4 ++--
 src/testdir/Make_all.mak |  6 ++++--
 src/testdir/test29.in    | 14 ++++++++++++++
 src/testdir/test29.ok    |  1 +
 4 files changed, 21 insertions(+), 4 deletions(-)
 create mode 100644 src/testdir/test29.in
 create mode 100644 src/testdir/test29.ok

diff --git a/src/buffer.c b/src/buffer.c
index 3b05f25d7f705b..147d20dc78f0ff 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2956,9 +2956,9 @@ ExpandBufnames(
     if (!fuzzy && patc != pat)
 	vim_free(patc);
 
-#ifdef FEAT_VIMINFO
     if (!fuzzy)
     {
+#ifdef FEAT_VIMINFO
 	if (matches != NULL)
 	{
 	    int i;
@@ -2978,13 +2978,13 @@ ExpandBufnames(
 	    }
 	    vim_free(matches);
 	}
+#endif
     }
     else
     {
 	if (fuzzymatches_to_strmatches(fuzmatch, file, count, FALSE) == FAIL)
 	    return FAIL;
     }
-#endif
 
     *num_file = count;
     return (count == 0 ? FAIL : OK);
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index bdf058c1ec43a1..7285354838805a 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -20,7 +20,8 @@ SCRIPTS_TINY = \
 	test24 \
 	test25 \
 	test26 \
-	test27
+	test27 \
+	test29
 
 SCRIPTS_TINY_OUT = \
 	test10.out \
@@ -31,7 +32,8 @@ SCRIPTS_TINY_OUT = \
 	test24.out \
 	test25.out \
 	test26.out \
-	test27.out
+	test27.out \
+	test29.out
 
 # Tests for Vim9 script.
 TEST_VIM9 = \
diff --git a/src/testdir/test29.in b/src/testdir/test29.in
new file mode 100644
index 00000000000000..047803c60ff7bd
--- /dev/null
+++ b/src/testdir/test29.in
@@ -0,0 +1,14 @@
+Test for buffer name completion when 'wildoptions' contains "fuzzy"
+(Confirm that Vim does not crash)
+
+STARTTEST
+:set wildoptions=fuzzy
+:new buf_a
+:b buf_a
+:q!
+:set wildoptions&
+:$w! test.out
+:qa!
+ENDTEST
+
+I'm alive!
diff --git a/src/testdir/test29.ok b/src/testdir/test29.ok
new file mode 100644
index 00000000000000..6a0a7c94510a8e
--- /dev/null
+++ b/src/testdir/test29.ok
@@ -0,0 +1 @@
+I'm alive!
