have a clear error when passing something > sys.maxsize to bytearray

This commit is contained in:
Benjamin Peterson 2010-04-16 22:35:38 +00:00
parent 5c4e292c14
commit 821a8ea39f
3 changed files with 15 additions and 7 deletions

View file

@ -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;