Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer

overflows.  Added few missed PyErr_NoMemory().
This commit is contained in:
Serhiy Storchaka 2015-02-16 13:28:22 +02:00
parent e1efc07a30
commit 1a1ff29659
15 changed files with 50 additions and 52 deletions

View file

@ -556,7 +556,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
/* Overallocate at most 10 characters. */
space = (isize > 10 ? 10 : isize) + isize;
osize = space;
output = PyMem_Malloc(space * sizeof(Py_UCS4));
output = PyMem_New(Py_UCS4, space);
if (!output) {
PyErr_NoMemory();
return NULL;
@ -703,7 +703,7 @@ nfc_nfkc(PyObject *self, PyObject *input, int k)
/* We allocate a buffer for the output.
If we find that we made no changes, we still return
the NFD result. */
output = PyMem_Malloc(len * sizeof(Py_UCS4));
output = PyMem_New(Py_UCS4, len);
if (!output) {
PyErr_NoMemory();
Py_DECREF(result);