diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-16 11:16:07 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-16 11:16:07 (GMT) |
commit | a2269d074b02440b7a9c22115454ad7e33aeb3f4 (patch) | |
tree | 308cd69b9f0f75f2d1a0074b15c39a5b043c48e9 /Python | |
parent | e8d750c05bba752215d842968dae24c151df561e (diff) | |
download | cpython-a2269d074b02440b7a9c22115454ad7e33aeb3f4.zip cpython-a2269d074b02440b7a9c22115454ad7e33aeb3f4.tar.gz cpython-a2269d074b02440b7a9c22115454ad7e33aeb3f4.tar.bz2 |
Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
overflows. Added few missed PyErr_NoMemory().
Diffstat (limited to 'Python')
-rw-r--r-- | Python/peephole.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Python/peephole.c b/Python/peephole.c index fb6cd03..e3bc004 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -242,7 +242,7 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts) static unsigned int * markblocks(unsigned char *code, Py_ssize_t len) { - unsigned int *blocks = (unsigned int *)PyMem_Malloc(len*sizeof(int)); + unsigned int *blocks = PyMem_New(unsigned int, len); int i,j, opcode, blockcnt = 0; if (blocks == NULL) { @@ -343,9 +343,11 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, goto exitUnchanged; /* Mapping to new jump targets after NOPs are removed */ - addrmap = (int *)PyMem_Malloc(codelen * sizeof(int)); - if (addrmap == NULL) + addrmap = PyMem_New(int, codelen); + if (addrmap == NULL) { + PyErr_NoMemory(); goto exitError; + } blocks = markblocks(codestr, codelen); if (blocks == NULL) |