diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2014-02-22 17:19:23 +0100 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2014-02-22 18:23:25 +0100 |
commit | e067e6b0cbdc45cb0ad4073b18cb18492810b035 (patch) | |
tree | 1a2a74caf3b75e6167862f0b053b2e49d655a6bc | |
parent | dd857489fcaa745ea569c523249fe37537bfe280 (diff) | |
download | numpy-e067e6b0cbdc45cb0ad4073b18cb18492810b035.tar.gz |
BUG: Whitespace stripping in pep3118 format parser and early free
Closes gh-3348
-rw-r--r-- | numpy/core/src/multiarray/buffer.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c index 4c1d476d5..b59729822 100644 --- a/numpy/core/src/multiarray/buffer.c +++ b/numpy/core/src/multiarray/buffer.c @@ -805,18 +805,19 @@ _descriptor_from_pep3118_format(char *s) if (*s == ':') { in_name = !in_name; *p = *s; + p++; } else if (in_name || !NumPyOS_ascii_isspace(*s)) { *p = *s; + p++; } - ++p; - ++s; + s++; } *p = '\0'; str = PyUString_FromStringAndSize(buf, strlen(buf)); - free(buf); if (str == NULL) { + free(buf); return NULL; } @@ -824,6 +825,7 @@ _descriptor_from_pep3118_format(char *s) _numpy_internal = PyImport_ImportModule("numpy.core._internal"); if (_numpy_internal == NULL) { Py_DECREF(str); + free(buf); return NULL; } descr = PyObject_CallMethod( @@ -833,14 +835,17 @@ _descriptor_from_pep3118_format(char *s) if (descr == NULL) { PyErr_Format(PyExc_ValueError, "'%s' is not a valid PEP 3118 buffer format string", buf); + free(buf); return NULL; } if (!PyArray_DescrCheck(descr)) { PyErr_Format(PyExc_RuntimeError, "internal error: numpy.core._internal._dtype_from_pep3118 " "did not return a valid dtype, got %s", buf); + free(buf); return NULL; } + free(buf); return (PyArray_Descr*)descr; } |