Patch 8.2.4668

4 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 2, 2022, 4:46:51 PM4/2/22
to vim...@googlegroups.com

Patch 8.2.4668
Problem: Buffer allocation failures insufficiently tested.
Solution: Add tests for memory allocation failures. (Yegappan Lakshmanan,
closes #10064)
Files: src/alloc.h, src/buffer.c, src/popupwin.c, src/window.c,
src/testdir/test_buffer.vim, src/testdir/test_swap.vim


*** ../vim-8.2.4667/src/alloc.h 2022-02-26 10:31:24.695882030 +0000
--- src/alloc.h 2022-04-02 21:41:06.477091336 +0100
***************
*** 40,44 ****
--- 40,45 ----
aid_sign_getplaced_list,
aid_insert_sign,
aid_sign_getinfo,
+ aid_buflistnew_bvars,
aid_last
} alloc_id_T;
*** ../vim-8.2.4667/src/buffer.c 2022-03-26 16:28:01.943874159 +0000
--- src/buffer.c 2022-04-02 21:41:06.477091336 +0100
***************
*** 2093,2099 ****
}
#ifdef FEAT_EVAL
// init b: variables
! buf->b_vars = dict_alloc();
if (buf->b_vars == NULL)
{
vim_free(ffname);
--- 2093,2099 ----
}
#ifdef FEAT_EVAL
// init b: variables
! buf->b_vars = dict_alloc_id(aid_buflistnew_bvars);
if (buf->b_vars == NULL)
{
vim_free(ffname);
*** ../vim-8.2.4667/src/popupwin.c 2022-04-02 15:31:48.301003446 +0100
--- src/popupwin.c 2022-04-02 21:41:06.477091336 +0100
***************
*** 1997,2003 ****
--- 1997,2006 ----
new_buffer = TRUE;
buf = buflist_new(NULL, NULL, (linenr_T)0, BLN_NEW|BLN_DUMMY|BLN_REUSE);
if (buf == NULL)
+ {
+ win_free_popup(wp);
return NULL;
+ }
ml_open(buf);

win_init_popup_win(wp, buf);
*** ../vim-8.2.4667/src/window.c 2022-03-26 16:28:01.943874159 +0000
--- src/window.c 2022-04-02 21:41:06.481091344 +0100
***************
*** 5256,5265 ****
void
win_free_popup(win_T *win)
{
! if (bt_popup(win->w_buffer))
! win_close_buffer(win, DOBUF_WIPE_REUSE, FALSE);
! else
! close_buffer(win, win->w_buffer, 0, FALSE, FALSE);
# if defined(FEAT_TIMERS)
if (win->w_popup_timer != NULL)
stop_timer(win->w_popup_timer);
--- 5256,5268 ----
void
win_free_popup(win_T *win)
{
! if (win->w_buffer != NULL)
! {
! if (bt_popup(win->w_buffer))
! win_close_buffer(win, DOBUF_WIPE_REUSE, FALSE);
! else
! close_buffer(win, win->w_buffer, 0, FALSE, FALSE);
! }
# if defined(FEAT_TIMERS)
if (win->w_popup_timer != NULL)
stop_timer(win->w_popup_timer);
*** ../vim-8.2.4667/src/testdir/test_buffer.vim 2021-12-02 12:30:17.417741511 +0000
--- src/testdir/test_buffer.vim 2022-04-02 21:41:06.477091336 +0100
***************
*** 430,433 ****
--- 430,503 ----
set maxmem& maxmemtot&
endfunc

+ " Test for a allocation failure when adding a new buffer
+ func Test_buflist_alloc_failure()
+ %bw!
+
+ edit Xfile1
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('edit Xfile2', 'E342:')
+
+ " test for bufadd()
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('call bufadd("Xbuffer")', 'E342:')
+
+ " test for setting the arglist
+ edit Xfile2
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('next Xfile3', 'E342:')
+
+ " test for setting the alternate buffer name when writing a file
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('write Xother', 'E342:')
+ call delete('Xother')
+
+ " test for creating a buffer using bufnr()
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails("call bufnr('Xnewbuf', v:true)", 'E342:')
+
+ " test for renaming buffer using :file
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('file Xnewfile', 'E342:')
+
+ " test for creating a buffer for a popup window
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('call popup_create("mypop", {})', 'E342:')
+
+ if has('terminal')
+ " test for creating a buffer for a terminal window
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('call term_start(&shell)', 'E342:')
+ %bw!
+ endif
+
+ " test for loading a new buffer after wiping out all the buffers
+ edit Xfile4
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('%bw!', 'E342:')
+
+ " test for :checktime loading the buffer
+ call writefile(['one'], 'Xfile5')
+ if has('unix')
+ edit Xfile5
+ " sleep for some time to make sure the timestamp is different
+ sleep 200m
+ call writefile(['two'], 'Xfile5')
+ set autoread
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('checktime', 'E342:')
+ set autoread&
+ bw!
+ endif
+
+ " test for :vimgrep loading a dummy buffer
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('vimgrep two Xfile5', 'E342:')
+ call delete('Xfile5')
+
+ " test for quickfix command loading a buffer
+ call test_alloc_fail(GetAllocId('buflistnew_bvars'), 0, 0)
+ call assert_fails('cexpr "Xfile6:10:Line10"', 'E342:')
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.4667/src/testdir/test_swap.vim 2021-10-19 22:12:21.936582330 +0100
--- src/testdir/test_swap.vim 2022-04-02 21:41:06.477091336 +0100
***************
*** 233,239 ****
autocmd SwapExists * let v:swapchoice = 'r'
augroup END

-
call mkdir('Xswap')
let $Xswap = 'foo' " Check for issue #4369.
set dir=Xswap//
--- 233,238 ----
*** ../vim-8.2.4667/src/version.c 2022-04-02 21:12:11.006733246 +0100
--- src/version.c 2022-04-02 21:42:49.769319911 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4668,
/**/

--
Shaw's Principle: Build a system that even a fool can use, and
only a fool will want to use it.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages