Skip to content

Commit a3070d5

Browse files
authored
bpo-31347: _PyObject_FastCall_Prepend: do not call memcpy if args might not be null (#3329)
Passing NULL as the second argument to to memcpy is undefined behavior even if the size is 0.
1 parent db56423 commit a3070d5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix possible undefined behavior in _PyObject_FastCall_Prepend.

Objects/call.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,9 @@ _PyObject_FastCall_Prepend(PyObject *callable,
854854

855855
/* use borrowed references */
856856
args2[0] = obj;
857-
memcpy(&args2[1],
858-
args,
859-
(nargs - 1)* sizeof(PyObject *));
857+
if (nargs > 1) {
858+
memcpy(&args2[1], args, (nargs - 1) * sizeof(PyObject *));
859+
}
860860

861861
result = _PyObject_FastCall(callable, args2, nargs);
862862
if (args2 != small_stack) {

0 commit comments

Comments
 (0)