Merged revisions 80126 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80126 | benjamin.peterson | 2010-04-16 17:35:38 -0500 (Fri, 16 Apr 2010) | 1 line have a clear error when passing something > sys.maxsize to bytearray ........
This commit is contained in:
parent
4c04583e79
commit
8380dd5aa4
|
@ -75,6 +75,7 @@ class BaseBytesTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(self.type2test('0', 'ascii'), b'0')
|
self.assertEqual(self.type2test('0', 'ascii'), b'0')
|
||||||
self.assertEqual(self.type2test(b'0'), b'0')
|
self.assertEqual(self.type2test(b'0'), b'0')
|
||||||
|
self.assertRaises(OverflowError, self.type2test, sys.maxsize + 1)
|
||||||
|
|
||||||
def test_constructor_type_errors(self):
|
def test_constructor_type_errors(self):
|
||||||
self.assertRaises(TypeError, self.type2test, 0.0)
|
self.assertRaises(TypeError, self.type2test, 0.0)
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #8417: Raise an OverflowError when an integer larger than sys.maxsize is
|
||||||
|
passed to bytes or bytearray.
|
||||||
|
|
||||||
- Issue #7301: Add environment variable $PYTHONWARNINGS.
|
- Issue #7301: Add environment variable $PYTHONWARNINGS.
|
||||||
|
|
||||||
- Issue #8329: Don't return the same lists from select.select when no fds are
|
- Issue #8329: Don't return the same lists from select.select when no fds are
|
||||||
|
|
|
@ -753,14 +753,18 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is it an int? */
|
/* Is it an int? */
|
||||||
count = PyNumber_AsSsize_t(arg, PyExc_ValueError);
|
count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
|
||||||
if (count == -1 && PyErr_Occurred())
|
if (count == -1 && PyErr_Occurred()) {
|
||||||
PyErr_Clear();
|
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
||||||
else {
|
|
||||||
if (count < 0) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
else
|
||||||
|
PyErr_Clear();
|
||||||
|
}
|
||||||
|
else if (count < 0) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (PyByteArray_Resize((PyObject *)self, count))
|
if (PyByteArray_Resize((PyObject *)self, count))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -2545,15 +2545,17 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
/* Is it an integer? */
|
/* Is it an integer? */
|
||||||
size = PyNumber_AsSsize_t(x, PyExc_ValueError);
|
size = PyNumber_AsSsize_t(x, PyExc_OverflowError);
|
||||||
if (size == -1 && PyErr_Occurred()) {
|
if (size == -1 && PyErr_Occurred()) {
|
||||||
|
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
||||||
|
return NULL;
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
}
|
}
|
||||||
|
else if (size < 0) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if (size < 0) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
new = PyBytes_FromStringAndSize(NULL, size);
|
new = PyBytes_FromStringAndSize(NULL, size);
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue