summaryrefslogtreecommitdiff
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-03 21:19:06 +0200
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-03 21:19:06 +0200
commitc64bcbec4bb3cdad320184b4155cdc05c55bb10d (patch)
tree8ec1034439e34c18e6d36a09f039345b1d223c69 /Objects/bytearrayobject.c
parent11f3f172e7081e2de0879dff86ded51109fa4e04 (diff)
downloadcpython-git-c64bcbec4bb3cdad320184b4155cdc05c55bb10d.tar.gz
#8401: assigning an int to a bytearray slice (e.g. b[3:4] = 5) now raises an error.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 55b4df638a..164c1cf3ca 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -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);