]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.1611: bufadd() reuses existing buffer without a name v8.1.1611
authorBram Moolenaar <Bram@vim.org>
Sun, 30 Jun 2019 18:33:01 +0000 (20:33 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 30 Jun 2019 18:33:01 +0000 (20:33 +0200)
Problem:    Bufadd() reuses existing buffer without a name.
Solution:   When the name is empty always create a new buffer.

src/evalfunc.c
src/testdir/test_functions.vim
src/version.c

index 954ea9fe9ad5d8dd35e1ff84430ef28635f5ee22..01afa3d4aa3029a9086082211f58b2d387ecfcbb 100644 (file)
@@ -1929,7 +1929,9 @@ find_buffer(typval_T *avar)
     static void
 f_bufadd(typval_T *argvars, typval_T *rettv)
 {
-    rettv->vval.v_number = buflist_add(tv_get_string(&argvars[0]), 0);
+    char_u *name = tv_get_string(&argvars[0]);
+
+    rettv->vval.v_number = buflist_add(*name == NUL ? NULL : name, 0);
 }
 
 /*
index 34a4bbf62f38596d6ed8894a921345d805f0f3f0..a08cef79d1bc1a346517832927dc9eeb91703e29 100644 (file)
@@ -1539,6 +1539,20 @@ func Test_bufadd_bufload()
   call assert_equal(['some', 'text'], getbufline(buf, 1, '$'))
   call assert_equal(curbuf, bufnr(''))
 
+  let buf1 = bufadd('')
+  let buf2 = bufadd('')
+  call assert_notequal(0, buf1)
+  call assert_notequal(0, buf2)
+  call assert_notequal(buf1, buf2)
+  call assert_equal(1, bufexists(buf1))
+  call assert_equal(1, bufexists(buf2))
+  call assert_equal(0, bufloaded(buf1))
+  exe 'bwipe ' .. buf1
+  call assert_equal(0, bufexists(buf1))
+  call assert_equal(1, bufexists(buf2))
+  exe 'bwipe ' .. buf2
+  call assert_equal(0, bufexists(buf2))
+
   bwipe someName
   bwipe otherName
   call assert_equal(0, bufexists('someName'))
index 6fce98b1f37da6f35437c455b0e3d3704f082e69..a1c5f88a89884b1755cf8d575f14bf0674134865 100644 (file)
@@ -777,6 +777,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1611,
 /**/
     1610,
 /**/