Patch 9.0.0947
Problem: Invalid memory access in substitute with function that goes to
another file.
Solution: Check for text locked in CTRL-W gf.
Files: src/normal.c, src/proto/normal.pro, src/window.c,
src/testdir/test_substitute.vim
*** ../vim-9.0.0946/src/normal.c 2022-11-23 20:19:17.133682464 +0000
--- src/normal.c 2022-11-25 12:15:55.563519734 +0000
***************
*** 188,194 ****
{
if (text_locked())
{
! clearopbeep(oap);
text_locked_msg();
return TRUE;
}
--- 188,195 ----
{
if (text_locked())
{
! if (oap != NULL)
! clearopbeep(oap);
text_locked_msg();
return TRUE;
}
***************
*** 196,201 ****
--- 197,221 ----
}
/*
+ * If text is locked, "curbuf_lock" or "allbuf_lock" is set:
+ * Give an error message, possibly beep and return TRUE.
+ * "oap" may be NULL.
+ */
+ int
+ check_text_or_curbuf_locked(oparg_T *oap)
+ {
+ if (check_text_locked(oap))
+ return TRUE;
+ if (curbuf_locked())
+ {
+ if (oap != NULL)
+ clearop(oap);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ /*
* Handle the count before a normal command and set cap->count0.
*/
static int
***************
*** 798,805 ****
goto normal_end;
}
! if ((nv_cmds[idx].cmd_flags & NV_NCW)
! && (check_text_locked(oap) || curbuf_locked()))
// this command is not allowed now
goto normal_end;
--- 818,824 ----
goto normal_end;
}
! if ((nv_cmds[idx].cmd_flags & NV_NCW) && check_text_or_curbuf_locked(oap))
// this command is not allowed now
goto normal_end;
***************
*** 4026,4038 ****
char_u *ptr;
linenr_T lnum = -1;
! if (check_text_locked(cap->oap))
return;
! if (curbuf_locked())
! {
! clearop(cap->oap);
! return;
! }
#ifdef FEAT_PROP_POPUP
if (ERROR_IF_TERM_POPUP_WINDOW)
return;
--- 4045,4053 ----
char_u *ptr;
linenr_T lnum = -1;
! if (check_text_or_curbuf_locked(cap->oap))
return;
!
#ifdef FEAT_PROP_POPUP
if (ERROR_IF_TERM_POPUP_WINDOW)
return;
*** ../vim-9.0.0946/src/proto/normal.pro 2022-06-27 23:15:17.000000000
+0100
--- src/proto/normal.pro 2022-11-25 12:16:38.815571913 +0000
***************
*** 1,4 ****
--- 1,5 ----
/* normal.c */
+ int check_text_or_curbuf_locked(oparg_T *oap);
void normal_cmd(oparg_T *oap, int toplevel);
void check_visual_highlight(void);
void end_visual_mode(void);
*** ../vim-9.0.0946/src/window.c 2022-11-23 14:32:57.970383432 +0000
--- src/window.c 2022-11-25 13:01:02.520690674 +0000
***************
*** 567,572 ****
--- 567,574 ----
case Ctrl_F:
wingotofile:
CHECK_CMDWIN;
+ if (check_text_or_curbuf_locked(NULL))
+ break;
ptr = grab_file_name(Prenum1, &lnum);
if (ptr != NULL)
***************
*** 885,891 ****
* When "new_wp" is NULL: split the current window in two.
* When "new_wp" is not NULL: insert this window at the far
* top/left/right/bottom.
! * return FAIL for failure, OK otherwise
*/
int
win_split_ins(
--- 887,893 ----
* When "new_wp" is NULL: split the current window in two.
* When "new_wp" is not NULL: insert this window at the far
* top/left/right/bottom.
! * Return FAIL for failure, OK otherwise.
*/
int
win_split_ins(
*** ../vim-9.0.0946/src/testdir/test_substitute.vim 2022-10-10
22:39:38.207545888 +0100
--- src/testdir/test_substitute.vim 2022-11-25 12:56:05.377444366 +0000
***************
*** 1096,1101 ****
--- 1096,1120 ----
bwipe!
endfunc
+ " This was editing another file from the expression.
+ func Test_sub_expr_goto_other_file()
+ call writefile([''], 'Xfileone', 'D')
+ enew!
+ call setline(1, ['a', 'b', 'c', 'd',
+ \ 'Xfileone zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'])
+
+ func g:SplitGotoFile()
+ exe "sil! norm 0\<C-W>gf"
+ return ''
+ endfunc
+
+ $
+ s/\%')/\=g:SplitGotoFile()
+
+ delfunc g:SplitGotoFile
+ bwipe!
+ endfunc
+
" Test for the 2-letter and 3-letter :substitute commands
func Test_substitute_short_cmd()
new
*** ../vim-9.0.0946/src/version.c 2022-11-25 00:57:02.099316757 +0000
--- src/version.c 2022-11-25 12:27:32.458583670 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 947,
/**/
--
I wish there was a knob on the TV to turn up the intelligence.
There's a knob called "brightness", but it doesn't seem to work.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20221125130356.5FA5E1C091A%40moolenaar.net.