Commit 821a8ea3 authored by Benjamin Peterson's avatar Benjamin Peterson

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

parent 5c4e292c
......@@ -73,6 +73,7 @@ class BaseBytesTest(unittest.TestCase):
self.assertEqual(self.type2test('0', 'ascii'), b'0')
self.assertEqual(self.type2test(b'0'), b'0')
self.assertRaises(OverflowError, self.type2test, sys.maxsize + 1)
def test_constructor_type_errors(self):
self.assertRaises(TypeError, self.type2test, 0.0)
......
......@@ -12,6 +12,9 @@ What's New in Python 2.7 beta 2?
Core and Builtins
-----------------
- Issue #8417: Raise an OverflowError when an integer larger than sys.maxsize is
passed to bytearray.
Library
-------
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment