Skip to content

Commit f52f9ea

Browse files
committed
patch 8.1.0118: duplicate error message for put command
Problem: Duplicate error message for put command. Solution: Check return value of u_save(). (Jason Franklin)
1 parent bd87eb3 commit f52f9ea

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

src/ops.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,9 +3551,10 @@ do_put(
35513551
return;
35523552
}
35533553

3554-
/* Autocommands may be executed when saving lines for undo, which may make
3555-
* y_array invalid. Start undo now to avoid that. */
3556-
u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1);
3554+
/* Autocommands may be executed when saving lines for undo. This might
3555+
* make "y_array" invalid, so we start undo now to avoid that. */
3556+
if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL)
3557+
goto end;
35573558

35583559
if (insert_string != NULL)
35593560
{

src/testdir/test_messages.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function Test_messages()
3939
endtry
4040
endfunction
4141

42-
" Patch 7.4.1696 defined the "clearmode()" command for clearing the mode
42+
" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
4343
" indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message
4444
" output could then be disturbed when 'cmdheight' was greater than one.
4545
" This test ensures that the bugfix for this issue remains in place.

src/testdir/test_put.vim

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc.
12

23
func Test_put_block()
34
if !has('multi_byte')
@@ -58,3 +59,48 @@ func Test_put_expr()
5859
call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1,'$'))
5960
bw!
6061
endfunc
62+
63+
func Test_put_fails_when_nomodifiable()
64+
new
65+
set nomodifiable
66+
67+
normal! yy
68+
call assert_fails(':put', 'E21')
69+
call assert_fails(':put!', 'E21')
70+
call assert_fails(':normal! p', 'E21')
71+
call assert_fails(':normal! gp', 'E21')
72+
call assert_fails(':normal! P', 'E21')
73+
call assert_fails(':normal! gP', 'E21')
74+
75+
if has('mouse')
76+
set mouse=n
77+
call assert_fails('execute "normal! \<MiddleMouse>"', 'E21')
78+
set mouse&
79+
endif
80+
81+
bwipeout!
82+
endfunc
83+
84+
" A bug was discovered where the Normal mode put commands (e.g., "p") would
85+
" output duplicate error messages when invoked in a non-modifiable buffer.
86+
func Test_put_p_errmsg_nodup()
87+
new
88+
set nomodifiable
89+
90+
normal! yy
91+
92+
func Capture_p_error()
93+
redir => s:p_err
94+
normal! p
95+
redir END
96+
endfunc
97+
98+
silent! call Capture_p_error()
99+
100+
" Error message output within a function should be three lines (the function
101+
" name, the line number, and the error message).
102+
call assert_equal(3, count(s:p_err, "\n"))
103+
104+
delfunction Capture_p_error
105+
bwipeout!
106+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ static char *(features[]) =
789789

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
118,
792794
/**/
793795
117,
794796
/**/

0 commit comments

Comments
 (0)