summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-08-19 04:23:20 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-08-19 04:23:20 (GMT)
commitfaa54a392951468090f0095ffa927b16fcb20ca4 (patch)
treea8586a5cc833217e6b1eaf4d052313475534178a /Objects/abstract.c
parent1836358c016cd7f5117f4f34fa3a27c5701e8265 (diff)
downloadcpython-faa54a392951468090f0095ffa927b16fcb20ca4.zip
cpython-faa54a392951468090f0095ffa927b16fcb20ca4.tar.gz
cpython-faa54a392951468090f0095ffa927b16fcb20ca4.tar.bz2
Code review of the new buffer protocol. Mostly add questions that should
be answered with the comments removed. There are many places that require checks when doing arithmetic for memory sizes when allocating memory. Otherwise, overflow is possible with a subsequent crash. Fix SF #1777057 which was a result of not initializing the new BufferError properly. Had to update the test for exceptions for BufferError too.
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index a48d5dc..4e25061 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -471,6 +471,7 @@ PyBuffer_ToContiguous(void *buf, PyBuffer *view, Py_ssize_t len, char fort)
/* Otherwise a more elaborate scheme is needed */
+ /* XXX(nnorwitz): need to check for overflow! */
indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*(view->ndim));
if (indices == NULL) {
PyErr_NoMemory();
@@ -521,6 +522,7 @@ PyBuffer_FromContiguous(PyBuffer *view, void *buf, Py_ssize_t len, char fort)
/* Otherwise a more elaborate scheme is needed */
+ /* XXX(nnorwitz): need to check for overflow! */
indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*(view->ndim));
if (indices == NULL) {
PyErr_NoMemory();
@@ -594,6 +596,7 @@ int PyObject_CopyData(PyObject *dest, PyObject *src)
/* Otherwise a more elaborate copy scheme is needed */
+ /* XXX(nnorwitz): need to check for overflow! */
indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*view_src.ndim);
if (indices == NULL) {
PyErr_NoMemory();
@@ -606,6 +609,7 @@ int PyObject_CopyData(PyObject *dest, PyObject *src)
}
elements = 1;
for (k=0; k<view_src.ndim; k++) {
+ /* XXX(nnorwitz): can this overflow? */
elements *= view_src.shape[k];
}
while (elements--) {