diff src/if_py_both.h @ 21198:8531ddd7dd63 v8.2.1150

patch 8.2.1150: ml_get error when using Python Commit: https://github.com/vim/vim/commit/bb790dcc46b74e6f9a1c4126be8a575f9fe73444 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jul 7 20:12:54 2020 +0200 patch 8.2.1150: ml_get error when using Python Problem: ml_get error when using Python. (Yegappan Lakshmanan) Solution: Check the line number is not out of range. Call "Check" with "fromObj" instead of "from".
author Bram Moolenaar <Bram@vim.org>
date Tue, 07 Jul 2020 20:15:04 +0200
parents 10eb6c38938c
children fb3dcd8ed14d
line wrap: on
line diff
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -3374,7 +3374,7 @@ OptionsItem(OptionsObject *self, PyObjec
     char_u	*stringval;
     PyObject	*todecref;
 
-    if (self->Check(self->from))
+    if (self->Check(self->fromObj))
 	return NULL;
 
     if (!(key = StringToChars(keyObject, &todecref)))
@@ -3565,7 +3565,7 @@ OptionsAssItem(OptionsObject *self, PyOb
     int		ret = 0;
     PyObject	*todecref;
 
-    if (self->Check(self->from))
+    if (self->Check(self->fromObj))
 	return -1;
 
     if (!(key = StringToChars(keyObject, &todecref)))
@@ -4334,10 +4334,15 @@ GetBufferLineList(buf_T *buf, PyInt lo, 
 
     for (i = 0; i < n; ++i)
     {
-	PyObject	*string = LineToString(
-		(char *)ml_get_buf(buf, (linenr_T)(lo+i), FALSE));
-
-	// Error check - was the Python string creation OK?
+	linenr_T	lnum = (linenr_T)(lo + i);
+	char		*text;
+	PyObject	*string;
+
+	if (lnum > buf->b_ml.ml_line_count)
+	    text = "";
+	else
+	    text = (char *)ml_get_buf(buf, lnum, FALSE);
+	string = LineToString(text);
 	if (string == NULL)
 	{
 	    Py_DECREF(list);