summaryrefslogtreecommitdiff
path: root/src/if_py_both.h
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-01-29 21:31:09 +0100
committerBram Moolenaar <Bram@vim.org>2017-01-29 21:31:09 +0100
commita58883b4ea0bbb813fd4dd7eb49dd6f03e3e5387 (patch)
tree5b4812b921817e5a8417c4cf62fcbcdc53cf3ec4 /src/if_py_both.h
parentd297f35eb0f6cfed47dd7ecf47df62994695a454 (diff)
downloadvim-git-a58883b4ea0bbb813fd4dd7eb49dd6f03e3e5387.tar.gz
patch 8.0.0265: may get ml_get error when :pydo deletes linesv8.0.0265
Problem: May get ml_get error when :pydo deletes lines or switches to another buffer. (Nikolai Pavlov, issue #1421) Solution: Check the buffer and line every time.
Diffstat (limited to 'src/if_py_both.h')
-rw-r--r--src/if_py_both.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/if_py_both.h b/src/if_py_both.h
index c44fc93ac..4cd373402 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -5619,6 +5619,7 @@ run_do(const char *cmd, void *arg UNUSED
int status;
PyObject *pyfunc, *pymain;
PyObject *run_ret;
+ buf_T *was_curbuf = curbuf;
if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK)
{
@@ -5671,7 +5672,9 @@ run_do(const char *cmd, void *arg UNUSED
#ifdef PY_CAN_RECURSE
*pygilstate = PyGILState_Ensure();
#endif
- if (!(line = GetBufferLine(curbuf, lnum)))
+ /* Check the line number, the command my have deleted lines. */
+ if (lnum > curbuf->b_ml.ml_line_count
+ || !(line = GetBufferLine(curbuf, lnum)))
goto err;
if (!(linenr = PyInt_FromLong((long) lnum)))
{
@@ -5684,9 +5687,19 @@ run_do(const char *cmd, void *arg UNUSED
if (!ret)
goto err;
+ /* Check that the command didn't switch to another buffer. */
+ if (curbuf != was_curbuf)
+ {
+ Py_XDECREF(ret);
+ goto err;
+ }
+
if (ret != Py_None)
if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL)
+ {
+ Py_XDECREF(ret);
goto err;
+ }
Py_XDECREF(ret);
PythonIO_Flush();