gh-122888: Fix crash on certain calls to str() (#122889)

Fixes #122888
This commit is contained in:
Jelle Zijlstra 2024-08-12 09:20:09 -07:00 committed by GitHub
parent 7c22ab5b38
commit 53ebb6232a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 12 deletions

View file

@ -15121,7 +15121,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);
}