Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
overflows. Added few missed PyErr_NoMemory().
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 @@
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 @@
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)