mirror of
https://github.com/python/cpython.git
synced 2026-01-18 13:19:59 +00:00
gh-143377: fix crashes in _interpreters.capture_exception (#143418)
This commit is contained in:
parent
e2f0160026
commit
ce6bae92da
3 changed files with 63 additions and 5 deletions
|
|
@ -1038,7 +1038,7 @@ _PyXIData_ReleaseAndRawFree(_PyXIData_t *xidata)
|
|||
/* convenience utilities */
|
||||
/*************************/
|
||||
|
||||
static const char *
|
||||
static char *
|
||||
_copy_string_obj_raw(PyObject *strobj, Py_ssize_t *p_size)
|
||||
{
|
||||
Py_ssize_t size = -1;
|
||||
|
|
@ -1139,11 +1139,16 @@ _format_TracebackException(PyObject *tbexc)
|
|||
}
|
||||
|
||||
Py_ssize_t size = -1;
|
||||
const char *formatted = _copy_string_obj_raw(formatted_obj, &size);
|
||||
char *formatted = _copy_string_obj_raw(formatted_obj, &size);
|
||||
Py_DECREF(formatted_obj);
|
||||
// We remove trailing the newline added by TracebackException.format().
|
||||
assert(formatted[size-1] == '\n');
|
||||
((char *)formatted)[size-1] = '\0';
|
||||
if (formatted == NULL || size == 0) {
|
||||
return formatted;
|
||||
}
|
||||
assert(formatted[size] == '\0');
|
||||
// Remove a trailing newline if needed.
|
||||
if (formatted[size-1] == '\n') {
|
||||
formatted[size-1] = '\0';
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue