summaryrefslogtreecommitdiff
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-08-19 04:23:20 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2007-08-19 04:23:20 +0000
commitf27e2eb4758d67121ecacce79d75917e10e809a8 (patch)
tree8eb961acf57fdde17be2e41b947302724a0199a5 /Objects/abstract.c
parent00033dbf403b08c9c0bfaaa1c0a54259ddb61cb9 (diff)
downloadcpython-f27e2eb4758d67121ecacce79d75917e10e809a8.tar.gz
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 a48d5dc992..4e250614e4 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--) {