From 892ae723ab95e429222e930cf41b32809567e58e Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 30 Jun 2019 20:33:01 +0200 Subject: [PATCH] patch 8.1.1611: bufadd() reuses existing buffer without a name Problem: Bufadd() reuses existing buffer without a name. Solution: When the name is empty always create a new buffer. --- src/evalfunc.c | 4 +++- src/testdir/test_functions.vim | 14 ++++++++++++++ src/version.c | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/evalfunc.c b/src/evalfunc.c index 954ea9fe9ad5d..01afa3d4aa302 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -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); } /* diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim index 34a4bbf62f385..a08cef79d1bc1 100644 --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -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')) diff --git a/src/version.c b/src/version.c index 6fce98b1f37da..a1c5f88a89884 100644 --- a/src/version.c +++ b/src/version.c @@ -777,6 +777,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1611, /**/ 1610, /**/