#8401: assigning an int to a bytearray slice (e.g. b[3:4] = 5) now raises an error.

This commit is contained in:
Ezio Melotti 2012-11-03 21:19:06 +02:00
parent 11f3f172e7
commit c64bcbec4b
3 changed files with 27 additions and 0 deletions

View file

@ -589,6 +589,12 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
needed = 0;
}
else if (values == (PyObject *)self || !PyByteArray_Check(values)) {
if (PyNumber_Check(values) || PyUnicode_Check(values)) {
PyErr_SetString(PyExc_TypeError,
"can assign only bytes, buffers, or iterables "
"of ints in range(0, 256)");
return -1;
}
/* Make a copy and call this function recursively */
int err;
values = PyByteArray_FromObject(values);