From 05da88878f239c17c898663a6c29d25f5485e216 Mon Sep 17 00:00:00 2001 From: AN Long Date: Mon, 22 Jun 2026 02:16:30 +0900 Subject: [PATCH] gh-151845: Fix formatfloat() return-value contract in unicode_format.c (GH-151846) Fix formatfloat() return-value contract in unicode_format.c (cherry picked from commit c2661e6189ab2833bf32fa723cc427e64c026839) Co-authored-by: AN Long --- Objects/unicode_format.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Objects/unicode_format.c b/Objects/unicode_format.c index e2790c8c1d4343..1d6f3f7d9a6f6a 100644 --- a/Objects/unicode_format.c +++ b/Objects/unicode_format.c @@ -159,8 +159,13 @@ formatfloat(PyObject *v, return -1; } } - else + else { *p_output = _PyUnicode_FromASCII(p, len); + if (*p_output == NULL) { + PyMem_Free(p); + return -1; + } + } PyMem_Free(p); return 0; }