# HG changeset patch
# User ZyX <[email protected]>
# Date 1367056810 -14400
# Branch python-extended-2
# Node ID 33094bb2285ee31aeb62197d3df680e9620fb7ac
# Parent 46fec64f3a319f3c3e8f5d39fb14661dc8c700d8
Fix a bunch of SEGV
CheckBuffer was launched too late in a big number of functions.
diff -r 46fec64f3a31 -r 33094bb2285e src/if_py_both.h
--- a/src/if_py_both.h Sat Apr 27 17:15:49 2013 +0400
+++ b/src/if_py_both.h Sat Apr 27 14:00:10 2013 +0400
@@ -2391,6 +2391,9 @@
if (CheckBuffer(self))
return NULL;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
if (n < 0 || n > end - start)
{
PyErr_SetString(PyExc_IndexError, _("line number out of range"));
@@ -2408,6 +2411,9 @@
if (CheckBuffer(self))
return NULL;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
size = end - start + 1;
if (lo < 0)
@@ -2432,6 +2438,9 @@
if (CheckBuffer(self))
return -1;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
if (n < 0 || n > end - start)
{
PyErr_SetString(PyExc_IndexError, _("line number out of range"));
@@ -2457,6 +2466,9 @@
if (CheckBuffer(self))
return -1;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
/* Sort out the slice range */
size = end - start + 1;
@@ -2493,6 +2505,9 @@
if (CheckBuffer(self))
return NULL;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
max = n = end - start + 1;
if (!PyArg_ParseTuple(args, "O|n", &lines, &n))
@@ -2700,15 +2715,13 @@
static PyObject *
BufferItem(PyObject *self, PyInt n)
{
- return RBItem((BufferObject *)(self), n, 1,
- (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count);
+ return RBItem((BufferObject *)(self), n, 1, -1);
}
static PyObject *
BufferSlice(PyObject *self, PyInt lo, PyInt hi)
{
- return RBSlice((BufferObject *)(self), lo, hi, 1,
- (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count);
+ return RBSlice((BufferObject *)(self), lo, hi, 1, -1);
}
static PyObject *
@@ -2732,9 +2745,7 @@
static PyObject *
BufferAppend(PyObject *self, PyObject *args)
{
- return RBAppend((BufferObject *)(self), args, 1,
- (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
- NULL);
+ return RBAppend((BufferObject *)(self), args, 1, -1, NULL);
}
static PyObject *
diff -r 46fec64f3a31 -r 33094bb2285e src/if_python.c
--- a/src/if_python.c Sat Apr 27 17:15:49 2013 +0400
+++ b/src/if_python.c Sat Apr 27 14:00:10 2013 +0400
@@ -1073,17 +1073,13 @@
static PyInt
BufferAssItem(PyObject *self, PyInt n, PyObject *val)
{
- return RBAsItem((BufferObject *)(self), n, val, 1,
- (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
- NULL);
+ return RBAsItem((BufferObject *)(self), n, val, 1, -1, NULL);
}
static PyInt
BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
{
- return RBAsSlice((BufferObject *)(self), lo, hi, val, 1,
- (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
- NULL);
+ return RBAsSlice((BufferObject *)(self), lo, hi, val, 1, -1, NULL);
}
static PySequenceMethods RangeAsSeq = {
diff -r 46fec64f3a31 -r 33094bb2285e src/if_python3.c
--- a/src/if_python3.c Sat Apr 27 17:15:49 2013 +0400
+++ b/src/if_python3.c Sat Apr 27 14:00:10 2013 +0400
@@ -1110,6 +1110,9 @@
{
Py_ssize_t start, stop, step, slicelen;
+ if (CheckBuffer((BufferObject *) self))
+ return NULL;
+
if (PySlice_GetIndicesEx((PyObject *)idx,
(Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
&start, &stop,
@@ -1139,6 +1142,9 @@
{
Py_ssize_t start, stop, step, slicelen;
+ if (CheckBuffer((BufferObject *) self))
+ return -1;
+
if (PySlice_GetIndicesEx((PyObject *)idx,
(Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
&start, &stop,
--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.
diff -cr vim.46fec64f3a31/src/if_py_both.h vim.33094bb2285e/src/if_py_both.h
*** vim.46fec64f3a31/src/if_py_both.h 2013-04-28 19:51:12.874191422 +0400
--- vim.33094bb2285e/src/if_py_both.h 2013-04-28 19:51:12.882191341 +0400
***************
*** 2391,2396 ****
--- 2391,2399 ----
if (CheckBuffer(self))
return NULL;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
if (n < 0 || n > end - start)
{
PyErr_SetString(PyExc_IndexError, _("line number out of range"));
***************
*** 2408,2413 ****
--- 2411,2419 ----
if (CheckBuffer(self))
return NULL;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
size = end - start + 1;
if (lo < 0)
***************
*** 2432,2437 ****
--- 2438,2446 ----
if (CheckBuffer(self))
return -1;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
if (n < 0 || n > end - start)
{
PyErr_SetString(PyExc_IndexError, _("line number out of range"));
***************
*** 2457,2462 ****
--- 2466,2474 ----
if (CheckBuffer(self))
return -1;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
/* Sort out the slice range */
size = end - start + 1;
***************
*** 2493,2498 ****
--- 2505,2513 ----
if (CheckBuffer(self))
return NULL;
+ if (end == -1)
+ end = self->buf->b_ml.ml_line_count;
+
max = n = end - start + 1;
if (!PyArg_ParseTuple(args, "O|n", &lines, &n))
***************
*** 2700,2714 ****
static PyObject *
BufferItem(PyObject *self, PyInt n)
{
! return RBItem((BufferObject *)(self), n, 1,
! (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count);
}
static PyObject *
BufferSlice(PyObject *self, PyInt lo, PyInt hi)
{
! return RBSlice((BufferObject *)(self), lo, hi, 1,
! (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count);
}
static PyObject *
--- 2715,2727 ----
static PyObject *
BufferItem(PyObject *self, PyInt n)
{
! return RBItem((BufferObject *)(self), n, 1, -1);
}
static PyObject *
BufferSlice(PyObject *self, PyInt lo, PyInt hi)
{
! return RBSlice((BufferObject *)(self), lo, hi, 1, -1);
}
static PyObject *
***************
*** 2732,2740 ****
static PyObject *
BufferAppend(PyObject *self, PyObject *args)
{
! return RBAppend((BufferObject *)(self), args, 1,
! (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
! NULL);
}
static PyObject *
--- 2745,2751 ----
static PyObject *
BufferAppend(PyObject *self, PyObject *args)
{
! return RBAppend((BufferObject *)(self), args, 1, -1, NULL);
}
static PyObject *
diff -cr vim.46fec64f3a31/src/if_python3.c vim.33094bb2285e/src/if_python3.c
*** vim.46fec64f3a31/src/if_python3.c 2013-04-28 19:51:12.872191441 +0400
--- vim.33094bb2285e/src/if_python3.c 2013-04-28 19:51:12.880191361 +0400
***************
*** 1110,1115 ****
--- 1110,1118 ----
{
Py_ssize_t start, stop, step, slicelen;
+ if (CheckBuffer((BufferObject *) self))
+ return NULL;
+
if (PySlice_GetIndicesEx((PyObject *)idx,
(Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
&start, &stop,
***************
*** 1139,1144 ****
--- 1142,1150 ----
{
Py_ssize_t start, stop, step, slicelen;
+ if (CheckBuffer((BufferObject *) self))
+ return -1;
+
if (PySlice_GetIndicesEx((PyObject *)idx,
(Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
&start, &stop,
diff -cr vim.46fec64f3a31/src/if_python.c vim.33094bb2285e/src/if_python.c
*** vim.46fec64f3a31/src/if_python.c 2013-04-28 19:51:12.877191391 +0400
--- vim.33094bb2285e/src/if_python.c 2013-04-28 19:51:12.885191311 +0400
***************
*** 1073,1089 ****
static PyInt
BufferAssItem(PyObject *self, PyInt n, PyObject *val)
{
! return RBAsItem((BufferObject *)(self), n, val, 1,
! (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
! NULL);
}
static PyInt
BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
{
! return RBAsSlice((BufferObject *)(self), lo, hi, val, 1,
! (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
! NULL);
}
static PySequenceMethods RangeAsSeq = {
--- 1073,1085 ----
static PyInt
BufferAssItem(PyObject *self, PyInt n, PyObject *val)
{
! return RBAsItem((BufferObject *)(self), n, val, 1, -1, NULL);
}
static PyInt
BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
{
! return RBAsSlice((BufferObject *)(self), lo, hi, val, 1, -1, NULL);
}
static PySequenceMethods RangeAsSeq = {