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
faa98155
Commit
faa98155
authored
Oct 02, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PyUnicode_ReadChar() raises a IndexError if the index in invalid
unicode_getitem() reuses PyUnicode_ReadChar()
parent
74203e68
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
14 deletions
+11
-14
Objects/unicodeobject.c
Objects/unicodeobject.c
+11
-14
No files found.
Objects/unicodeobject.c
View file @
faa98155
...
...
@@ -2840,8 +2840,12 @@ PyUnicode_GetLength(PyObject *unicode)
Py_UCS4
PyUnicode_ReadChar
(
PyObject
*
unicode
,
Py_ssize_t
index
)
{
if
(
!
PyUnicode_Check
(
unicode
)
||
PyUnicode_READY
(
unicode
)
!=
-
1
)
{
return
PyErr_BadArgument
();
if
(
!
PyUnicode_Check
(
unicode
)
||
PyUnicode_READY
(
unicode
)
==
-
1
)
{
PyErr_BadArgument
();
return
(
Py_UCS4
)
-
1
;
}
if
(
index
<
0
||
index
>=
_PyUnicode_LENGTH
(
unicode
))
{
PyErr_SetString
(
PyExc_IndexError
,
"string index out of range"
);
return
(
Py_UCS4
)
-
1
;
}
return
PyUnicode_READ_CHAR
(
unicode
,
index
);
...
...
@@ -9808,18 +9812,11 @@ unicode_find(PyObject *self, PyObject *args)
}
static
PyObject
*
unicode_getitem
(
Py
Unicode
Object
*
self
,
Py_ssize_t
index
)
unicode_getitem
(
PyObject
*
self
,
Py_ssize_t
index
)
{
Py_UCS4
ch
;
if
(
PyUnicode_READY
(
self
)
==
-
1
)
return
NULL
;
if
(
index
<
0
||
index
>=
_PyUnicode_LENGTH
(
self
))
{
PyErr_SetString
(
PyExc_IndexError
,
"string index out of range"
);
Py_UCS4
ch
=
PyUnicode_ReadChar
(
self
,
index
);
if
(
ch
==
(
Py_UCS4
)
-
1
)
return
NULL
;
}
ch
=
PyUnicode_READ
(
PyUnicode_KIND
(
self
),
PyUnicode_DATA
(
self
),
index
);
return
PyUnicode_FromOrdinal
(
ch
);
}
...
...
@@ -10475,7 +10472,7 @@ PyUnicode_Substring(PyObject *self, Py_ssize_t start, Py_ssize_t end)
length
=
end
-
start
;
if
(
length
==
1
)
return
unicode_getitem
(
(
PyUnicodeObject
*
)
self
,
start
);
return
unicode_getitem
(
self
,
start
);
if
(
start
<
0
||
end
<
0
)
{
PyErr_SetString
(
PyExc_IndexError
,
"string index out of range"
);
...
...
@@ -11758,7 +11755,7 @@ unicode_subscript(PyUnicodeObject* self, PyObject* item)
return
NULL
;
if
(
i
<
0
)
i
+=
PyUnicode_GET_LENGTH
(
self
);
return
unicode_getitem
(
self
,
i
);
return
unicode_getitem
(
(
PyObject
*
)
self
,
i
);
}
else
if
(
PySlice_Check
(
item
))
{
Py_ssize_t
start
,
stop
,
step
,
slicelength
,
cur
,
i
;
const
Py_UNICODE
*
source_buf
;
...
...
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