diff src/if_ruby.c @ 10761:721af7a9b4b4 v8.0.0270

patch 8.0.0270: may get ml_get error when :rubydo deletes lines commit https://github.com/vim/vim/commit/c593fee0e5e850f7e75be41f5d1751f28892a27f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 29 23:11:25 2017 +0100 patch 8.0.0270: may get ml_get error when :rubydo deletes lines Problem: May get ml_get error when :rubydo deletes lines or switches to another buffer. (Nikolai Pavlov, issue https://github.com/vim/vim/issues/1421) Solution: Check the buffer and line every time.
author Christian Brabandt <cb@256bit.org>
date Sun, 29 Jan 2017 23:15:50 +0100
parents df1abc85b169
children df498e3e34fc
line wrap: on
line diff
--- a/src/if_ruby.c
+++ b/src/if_ruby.c
@@ -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))
 	    {