]> granicus.if.org Git - vim/commitdiff
patch 8.0.0270: may get ml_get error when :rubydo deletes lines v8.0.0270
authorBram Moolenaar <Bram@vim.org>
Sun, 29 Jan 2017 22:11:25 +0000 (23:11 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 29 Jan 2017 22:11:25 +0000 (23:11 +0100)
Problem:    May get ml_get error when :rubydo deletes lines or switches to
            another buffer. (Nikolai Pavlov, issue #1421)
Solution:   Check the buffer and line every time.

src/if_ruby.c
src/testdir/test_ruby.vim
src/version.c

index afa27abe2ca5f8aead825b91967012c252abc391..02b59dd14a2b9da474d365dff6d043e78914e660 100644 (file)
@@ -783,6 +783,7 @@ void ex_rubydo(exarg_T *eap)
 {
     int state;
     linenr_T i;
+    buf_T   *was_curbuf = curbuf;
 
     if (ensure_ruby_initialized())
     {
@@ -792,6 +793,8 @@ void ex_rubydo(exarg_T *eap)
        {
            VALUE line;
 
+           if (i > curbuf->b_ml.ml_line_count)
+               break;
            line = vim_str2rb_enc_str((char *)ml_get(i));
            rb_lastline_set(line);
            eval_enc_string_protect((char *) eap->arg, &state);
@@ -800,6 +803,8 @@ void ex_rubydo(exarg_T *eap)
                error_print(state);
                break;
            }
+           if (was_curbuf != curbuf)
+               break;
            line = rb_lastline_get();
            if (!NIL_P(line))
            {
index 106ccb48c3ed59038aaa58e95b880a52cc947148..174467f71f0e2bd2fc85b8f5d03cd2731e1658de 100644 (file)
@@ -32,3 +32,20 @@ func Test_ruby_evaluate_dict()
   redir END
   call assert_equal(['{"a"=>"foo", "b"=>123}'], split(l:out, "\n"))
 endfunc
+
+func Test_rubydo()
+  " Check deleting lines does not trigger ml_get error.
+  new
+  call setline(1, ['one', 'two', 'three'])
+  rubydo Vim.command("%d_")
+  bwipe!
+
+  " Check switching to another buffer does not trigger ml_get error.
+  new
+  let wincount = winnr('$')
+  call setline(1, ['one', 'two', 'three'])
+  rubydo Vim.command("new")
+  call assert_equal(wincount + 1, winnr('$'))
+  bwipe!
+  bwipe!
+endfunc
index 476074f6b2faef183217fe35856e7005433c0033..44e5b6fb576dc13d519a69a70472d4abcd0b8c0e 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    270,
 /**/
     269,
 /**/