@@ -361,11 +361,8 @@ partial_descr_get(PyObject *self, PyObject *obj, PyObject *type)
361361 stack = small_stack; \
362362 } \
363363 else { \
364+ /* NOTE, size * elsize in theory could overflow */ \
364365 stack = PyMem_Malloc (size * elsize ); \
365- if (stack == NULL) { \
366- PyErr_NoMemory(); \
367- return NULL; \
368- } \
369366 } \
370367 } while (0 )
371368
@@ -438,12 +435,17 @@ partial_vectorcall(PyObject *self, PyObject *const *args,
438435 Py_ssize_t tot_nargskw = tot_nargs + tot_nkwds ;
439436
440437 PyObject * * stack , * small_stack [_PY_FASTCALL_SMALL_STACK ];
441- PyObject * tot_kwnames = kwnames ;
438+ PyObject * tot_kwnames ;
442439
443440 /* Initialize stack & copy keywords to stack */
444441 if (!pto_nkwds ) {
445442 /* Allocate Stack */
446443 ALLOCATE_STACK (sizeof (PyObject * ), tot_nargskw , small_stack , stack );
444+ if (stack == NULL ) {
445+ PyErr_NoMemory ();
446+ return NULL ;
447+ }
448+ tot_kwnames = kwnames ;
447449
448450 if (nkwds ) {
449451 /* if !pto_nkwds & nkwds, then simply append kw */
@@ -457,6 +459,10 @@ partial_vectorcall(PyObject *self, PyObject *const *args,
457459 /* Temporary stack for keywords that are not in pto->kw */
458460 PyObject * * kwtail , * small_kwtail [_PY_FASTCALL_SMALL_STACK * 2 ];
459461 ALLOCATE_STACK (sizeof (PyObject * ), nkwds * 2 , small_kwtail , kwtail );
462+ if (kwtail == NULL ) {
463+ PyErr_NoMemory ();
464+ return NULL ;
465+ }
460466
461467 /* Merge kw to pto_kw or add to tail (if not duplicate) */
462468 Py_ssize_t n_tail = 0 ;
@@ -489,6 +495,11 @@ partial_vectorcall(PyObject *self, PyObject *const *args,
489495 tot_nkwds = pto_nkwds + nkwds - n_merges ;
490496 tot_nargskw = tot_nargs + tot_nkwds ;
491497 ALLOCATE_STACK (sizeof (PyObject * ), tot_nargskw , small_stack , stack );
498+ if (stack == NULL ) {
499+ Py_XDECREF (pto_kw );
500+ PyErr_NoMemory ();
501+ return NULL ;
502+ }
492503 tot_kwnames = PyTuple_New (tot_nkwds );
493504
494505 /* Copy pto_kw to stack */
@@ -545,6 +556,9 @@ partial_vectorcall(PyObject *self, PyObject *const *args,
545556 return ret ;
546557}
547558
559+ #undef ALLOCATE_STACK
560+ #undef DEALLOCATE_STACK
561+
548562/* Set pto->vectorcall depending on the parameters of the partial object */
549563static void
550564partial_setvectorcall (partialobject * pto )
@@ -561,6 +575,7 @@ partial_setvectorcall(partialobject *pto)
561575 }
562576}
563577
578+
564579// Not converted to argument clinic, because of `*args, **kwargs` arguments.
565580static PyObject *
566581partial_call (PyObject * self , PyObject * args , PyObject * kwargs )
0 commit comments