mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #29159: Fix regression in bytes(x) when x.__index__() raises Exception.
This commit is contained in:
parent
a251fb02f4
commit
a634e23209
4 changed files with 41 additions and 18 deletions
|
@ -798,18 +798,22 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
|
|||
if (PyIndex_Check(arg)) {
|
||||
count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
|
||||
if (count == -1 && PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
if (count < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||
return -1;
|
||||
}
|
||||
if (count > 0) {
|
||||
if (PyByteArray_Resize((PyObject *)self, count))
|
||||
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
||||
return -1;
|
||||
memset(PyByteArray_AS_STRING(self), 0, count);
|
||||
PyErr_Clear(); /* fall through */
|
||||
}
|
||||
else {
|
||||
if (count < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||
return -1;
|
||||
}
|
||||
if (count > 0) {
|
||||
if (PyByteArray_Resize((PyObject *)self, count))
|
||||
return -1;
|
||||
memset(PyByteArray_AS_STRING(self), 0, count);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Use the buffer API */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue