10000 gh-101037: Fix potential memory underallocation for zeros of int subtypes by mdickinson · Pull Request #101038 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-101037: Fix potential memory underallocation for zeros of int subtypes #101038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-101037: Fix memory allocation for zeros of int subtypes
  • Loading branch information
mdickinson authored and corona10 committed Jan 19, 2023
commit 61adba0d65f416e3bf285b5881ce8705d1647f7b
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