summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-05-16 19:15:57 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-05-16 19:15:57 (GMT)
commitc742dff16a8dd6979a7857948f63f99f391bb369 (patch)
treece6e437720348a246ad3ee677d1f18e980b86198 /Objects/bytearrayobject.c
parent3079bbebac4e455bec8e3f2e983daf63503af196 (diff)
downloadcpython-c742dff16a8dd6979a7857948f63f99f391bb369.zip
cpython-c742dff16a8dd6979a7857948f63f99f391bb369.tar.gz
cpython-c742dff16a8dd6979a7857948f63f99f391bb369.tar.bz2
Issue #27039: Fixed bytearray.remove() for values greater than 127.
Patch by Joe Jevnik.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 3db3591..a90bdeb 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -2395,23 +2395,21 @@ static PyObject *
bytearray_remove(PyByteArrayObject *self, PyObject *arg)
{
int value;
- Py_ssize_t where, n = Py_SIZE(self);
+ Py_ssize_t n = Py_SIZE(self);
+ char *where;
if (! _getbytevalue(arg, &value))
return NULL;
- for (where = 0; where < n; where++) {
- if (self->ob_bytes[where] == value)
- break;
- }
- if (where == n) {
+ where = memchr(self->ob_bytes, value, n);
+ if (!where) {
PyErr_SetString(PyExc_ValueError, "value not found in bytearray");
return NULL;
}
if (!_canresize(self))
return NULL;
- memmove(self->ob_bytes + where, self->ob_bytes + where + 1, n - where);
+ memmove(where, where + 1, self->ob_bytes + n - where);
if (PyByteArray_Resize((PyObject *)self, n - 1) < 0)
return NULL;