From 6f7d69ae4718de29b37f54abcfed44015ae57d97 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Sat, 12 Jul 2008 05:14:39 +0000 Subject: Coding style cleanups. Check return of PyArray_DescrNew for NULL (possible memory error). --- numpy/core/src/arraytypes.inc.src | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'numpy/core/src') diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src index 6b07c95f5..29c581f55 100644 --- a/numpy/core/src/arraytypes.inc.src +++ b/numpy/core/src/arraytypes.inc.src @@ -2475,42 +2475,51 @@ static PyArray_Descr *_builtin_descrs[] = { static PyArray_Descr * PyArray_DescrFromType(int type) { - PyArray_Descr *ret=NULL; + PyArray_Descr *ret = NULL; if (type < PyArray_NTYPES) { ret = _builtin_descrs[type]; } else if (type == PyArray_NOTYPE) { - /* This needs to not raise an error so - that PyArray_DescrFromType(PyArray_NOTYPE) - works for backwards-compatible C-API + /* + * This needs to not raise an error so + * that PyArray_DescrFromType(PyArray_NOTYPE) + * works for backwards-compatible C-API */ return NULL; } - else if ((type == PyArray_CHAR) || \ - (type == PyArray_CHARLTR)) { + else if ((type == PyArray_CHAR) || (type == PyArray_CHARLTR)) { ret = PyArray_DescrNew(_builtin_descrs[PyArray_STRING]); + + if (ret == NULL) { + return NULL; + } ret->elsize = 1; ret->type = PyArray_CHARLTR; return ret; } - else if PyTypeNum_ISUSERDEF(type) { - ret = userdescrs[type-PyArray_USERDEF]; + else if (PyTypeNum_ISUSERDEF(type)) { + ret = userdescrs[type - PyArray_USERDEF]; } else { - int num=PyArray_NTYPES; - if (type < _MAX_LETTER) + int num = PyArray_NTYPES; + if (type < _MAX_LETTER) { num = (int) _letter_to_num[type]; - if (num >= PyArray_NTYPES) + } + if (num >= PyArray_NTYPES) { ret = NULL; - else + } + else { ret = _builtin_descrs[num]; + } } - if (ret==NULL) { + if (ret == NULL) { PyErr_SetString(PyExc_ValueError, "Invalid data-type for array"); } - else Py_INCREF(ret); + else { + Py_INCREF(ret); + } return ret; } -- cgit v1.2.1