[3.13] gh-122888: Fix crash on certain calls to str() (GH-122889) (#122947)

Fixes GH-122888
(cherry picked from commit 53ebb6232a)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-08-12 18:53:05 +02:00 committed by GitHub
parent 8b64ce4eb4
commit 55aede7342
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 12 deletions

View file

@ -14817,7 +14817,16 @@ unicode_vectorcall(PyObject *type, PyObject *const *args,
return PyObject_Str(object);
}
const char *encoding = arg_as_utf8(args[1], "encoding");
const char *errors = (nargs == 3) ? arg_as_utf8(args[2], "errors") : NULL;
if (encoding == NULL) {
return NULL;
}
const char *errors = NULL;
if (nargs == 3) {
errors = arg_as_utf8(args[2], "errors");
if (errors == NULL) {
return NULL;
}
}
return PyUnicode_FromEncodedObject(object, encoding, errors);
}