History

ext/aubioproxy.c: improve sizes checks, cast to uint_t

Paul Brossier committed 12 years ago

Commit 3194dca1 parent 906c0a21 file · +21 −3Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/ext/aubioproxy.c+21−3
@@ -35,7 +35,13 @@ PyAubio_ArrayToCFvec (PyObject *input) { · 34 unmodified lines
35 // vec = new_fvec (vec->length);35 // vec = new_fvec (vec->length);
36 // no need to really allocate fvec, just its struct member36 // no need to really allocate fvec, just its struct member
37 vec = (fvec_t *)malloc(sizeof(fvec_t));37 vec = (fvec_t *)malloc(sizeof(fvec_t));
38 vec->length = PyArray_SIZE ((PyArrayObject *)array);38 long length = PyArray_SIZE ((PyArrayObject *)array);
39 if (length > 0) {
40 vec->length = (uint_t)length;
41 } else {
42 PyErr_SetString (PyExc_ValueError, "input array size should be greater than 0");
43 goto fail;
44 }
39 vec->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)array, 0);45 vec->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)array, 0);
40 46
41 } else if (PyObject_TypeCheck (input, &PyList_Type)) {47 } else if (PyObject_TypeCheck (input, &PyList_Type)) {
@@ -130,8 +136,20 @@ PyAubio_ArrayToCFmat (PyObject *input) { · 88 unmodified lines
130 136
131 // no need to really allocate fvec, just its struct member137 // no need to really allocate fvec, just its struct member
132 mat = (fmat_t *)malloc(sizeof(fmat_t));138 mat = (fmat_t *)malloc(sizeof(fmat_t));
133 mat->length = PyArray_DIM ((PyArrayObject *)array, 1);139 long length = PyArray_DIM ((PyArrayObject *)array, 1);
134 mat->height = PyArray_DIM ((PyArrayObject *)array, 0);140 if (length > 0) {
141 mat->length = (uint_t)length;
142 } else {
143 PyErr_SetString (PyExc_ValueError, "input array dimension 1 should be greater than 0");
144 goto fail;
145 }
146 long height = PyArray_DIM ((PyArrayObject *)array, 0);
147 if (height > 0) {
148 mat->height = (uint_t)height;
149 } else {
150 PyErr_SetString (PyExc_ValueError, "input array dimension 0 should be greater than 0");
151 goto fail;
152 }
135 mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height);153 mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height);
136 for (i=0; i< mat->height; i++) {154 for (i=0; i< mat->height; i++) {
137 mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)array, i);155 mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)array, i);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t