mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
have a clear error when passing something > sys.maxsize to bytearray
This commit is contained in:
parent
5c4e292c14
commit
821a8ea39f
3 changed files with 15 additions and 7 deletions
|
@ -824,14 +824,18 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
|
|||
}
|
||||
|
||||
/* Is it an int? */
|
||||
count = PyNumber_AsSsize_t(arg, PyExc_ValueError);
|
||||
if (count == -1 && PyErr_Occurred())
|
||||
PyErr_Clear();
|
||||
else {
|
||||
if (count < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||
count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
|
||||
if (count == -1 && PyErr_Occurred()) {
|
||||
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
PyErr_Clear();
|
||||
}
|
||||
else if (count < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
if (count > 0) {
|
||||
if (PyByteArray_Resize((PyObject *)self, count))
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue