Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
92709a26
Commit
92709a26
authored
Sep 09, 2019
by
Sergey Fedoseev
Committed by
T. Wouters
Sep 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-37840: Fix handling of negative indices in bytearray_getitem() (GH-15250)
parent
915cd3f0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
2 deletions
+24
-2
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+9
-0
Misc/NEWS.d/next/Core and Builtins/2019-08-13-18-05-20.bpo-37840.elLCci.rst
...ore and Builtins/2019-08-13-18-05-20.bpo-37840.elLCci.rst
+2
-0
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+13
-0
Objects/bytearrayobject.c
Objects/bytearrayobject.c
+0
-2
No files found.
Lib/test/test_bytes.py
View file @
92709a26
...
...
@@ -962,6 +962,15 @@ class BaseBytesTest:
c
=
b
.
translate
(
None
,
delete
=
b'e'
)
self
.
assertEqual
(
c
,
b'hllo'
)
def
test_sq_item
(
self
):
_testcapi
=
test
.
support
.
import_module
(
'_testcapi'
)
obj
=
self
.
type2test
((
42
,))
with
self
.
assertRaises
(
IndexError
):
_testcapi
.
sequence_getitem
(
obj
,
-
2
)
with
self
.
assertRaises
(
IndexError
):
_testcapi
.
sequence_getitem
(
obj
,
1
)
self
.
assertEqual
(
_testcapi
.
sequence_getitem
(
obj
,
0
),
42
)
class
BytesTest
(
BaseBytesTest
,
unittest
.
TestCase
):
type2test
=
bytes
...
...
Misc/NEWS.d/next/Core and Builtins/2019-08-13-18-05-20.bpo-37840.elLCci.rst
0 → 100644
View file @
92709a26
Fix handling of negative indices in :c:member:`~PySequenceMethods.sq_item`
of :class:`bytearray`. Patch by Sergey Fedoseev.
Modules/_testcapimodule.c
View file @
92709a26
...
...
@@ -5164,6 +5164,18 @@ test_write_unraisable_exc(PyObject *self, PyObject *args)
}
static
PyObject
*
sequence_getitem
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
seq
;
Py_ssize_t
i
;
if
(
!
PyArg_ParseTuple
(
args
,
"On"
,
&
seq
,
&
i
))
{
return
NULL
;
}
return
PySequence_GetItem
(
seq
,
i
);
}
static
PyMethodDef
TestMethods
[]
=
{
{
"raise_exception"
,
raise_exception
,
METH_VARARGS
},
{
"raise_memoryerror"
,
raise_memoryerror
,
METH_NOARGS
},
...
...
@@ -5413,6 +5425,7 @@ static PyMethodDef TestMethods[] = {
{
"negative_refcount"
,
negative_refcount
,
METH_NOARGS
},
#endif
{
"write_unraisable_exc"
,
test_write_unraisable_exc
,
METH_VARARGS
},
{
"sequence_getitem"
,
sequence_getitem
,
METH_VARARGS
},
{
NULL
,
NULL
}
/* sentinel */
};
...
...
Objects/bytearrayobject.c
View file @
92709a26
...
...
@@ -381,8 +381,6 @@ bytearray_irepeat(PyByteArrayObject *self, Py_ssize_t count)
static
PyObject
*
bytearray_getitem
(
PyByteArrayObject
*
self
,
Py_ssize_t
i
)
{
if
(
i
<
0
)
i
+=
Py_SIZE
(
self
);
if
(
i
<
0
||
i
>=
Py_SIZE
(
self
))
{
PyErr_SetString
(
PyExc_IndexError
,
"bytearray index out of range"
);
return
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment