Skip to content

Commit

Permalink
pythongh-101037: Fix memory allocation for zeros of int subtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson committed Jan 14, 2023
1 parent ef633e5 commit ee51432
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix potential memory underallocation issue for instances of :class:`int`
subclasses with value zero.
5 changes: 5 additions & 0 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5638,6 +5638,11 @@ long_subtype_new(PyTypeObject *type, PyObject *x, PyObject *obase)
n = Py_SIZE(tmp);
if (n < 0)
n = -n;
/* Fast operations for single digit integers (including zero)
* assume that there is always at least one digit present. */
if (n == 0) {
n = 1;
}
newobj = (PyLongObject *)type->tp_alloc(type, n);
if (newobj == NULL) {
Py_DECREF(tmp);
Expand Down

0 comments on commit ee51432

Please sign in to comment.