diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.173d49.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.173d49.rst new file mode 100644 index 00000000000000..a552d06ff7bb89 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.173d49.rst @@ -0,0 +1,2 @@ +Avoid a crash if formatting an integer with the ``c`` presentation type runs +out of memory. diff --git a/Objects/unicode_formatter.c b/Objects/unicode_formatter.c index b8604d1355940a..252c317b0f6909 100644 --- a/Objects/unicode_formatter.c +++ b/Objects/unicode_formatter.c @@ -1256,6 +1256,9 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format, goto done; } tmp = PyUnicode_FromOrdinal(x); + if (tmp == NULL) { + goto done; + } inumeric_chars = 0; n_digits = 1; maxchar = Py_MAX(maxchar, (Py_UCS4)x);