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:
Benjamin Peterson 2010-04-16 22:51:37 +00:00
parent 4c04583e79
commit 8380dd5aa4
4 changed files with 22 additions and 12 deletions

View file

@ -2545,15 +2545,17 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return new;
}
/* Is it an integer? */
size = PyNumber_AsSsize_t(x, PyExc_ValueError);
size = PyNumber_AsSsize_t(x, PyExc_OverflowError);
if (size == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
return NULL;
PyErr_Clear();
}
else if (size < 0) {
PyErr_SetString(PyExc_ValueError, "negative count");
return NULL;
}
else {
if (size < 0) {
PyErr_SetString(PyExc_ValueError, "negative count");
return NULL;
}
new = PyBytes_FromStringAndSize(NULL, size);
if (new == NULL) {
return NULL;