summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2004-09-24 15:41:27 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2004-09-24 15:41:27 (GMT)
commitfb6ba07d9c6cccee260a70aef8f3cf52c5d26776 (patch)
treea76ef41557b7baf35089639f637225cb6bdf2dc0 /Objects
parent29302a7867f610c7162ec325ca9e23869b3e07a0 (diff)
downloadcpython-fb6ba07d9c6cccee260a70aef8f3cf52c5d26776.zip
cpython-fb6ba07d9c6cccee260a70aef8f3cf52c5d26776.tar.gz
cpython-fb6ba07d9c6cccee260a70aef8f3cf52c5d26776.tar.bz2
Fix buffer offset calculation (need to compute it before changing
'base'). Fixes SF bug #1033720. Move offset sanity checking to buffer_from_memory().
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bufferobject.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c
index 6adf838..e0344d8 100644
--- a/Objects/bufferobject.c
+++ b/Objects/bufferobject.c
@@ -66,6 +66,11 @@ buffer_from_memory(PyObject *base, int size, int offset, void *ptr,
"size must be zero or positive");
return NULL;
}
+ if (offset < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "offset must be zero or positive");
+ return NULL;
+ }
b = PyObject_NEW(PyBufferObject, &PyBuffer_Type);
if ( b == NULL )
@@ -85,20 +90,11 @@ buffer_from_memory(PyObject *base, int size, int offset, void *ptr,
static PyObject *
buffer_from_object(PyObject *base, int size, int offset, int readonly)
{
- if ( offset < 0 ) {
- PyErr_SetString(PyExc_ValueError,
- "offset must be zero or positive");
- return NULL;
- }
-
- /* if the base object is another buffer, then try to refer to the
- * base object.
- */
if ( PyBuffer_Check(base) && (((PyBufferObject *)base)->b_base) ) {
+ /* another buffer, refer to the base object */
+ offset += ((PyBufferObject *)base)->b_offset;
base = ((PyBufferObject *)base)->b_base;
- offset = ((PyBufferObject *)base)->b_offset + offset;
}
-
return buffer_from_memory(base, size, offset, NULL, readonly);
}