Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(46099)

Unified Diff: Objects/unicodeobject.c

Issue 28822: Fix indices handling in PyUnicode_FindChar
Patch Set: Created 2 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Lib/test/test_unicode.py ('K') | « Modules/_testcapimodule.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Objects/unicodeobject.c Tue Nov 29 09:56:07 2016 +0200
+++ b/Objects/unicodeobject.c Tue Nov 29 23:46:20 2016 +0800
@@ -9461,16 +9461,12 @@
int direction)
{
int kind;
- Py_ssize_t result;
+ Py_ssize_t len, result;
if (PyUnicode_READY(str) == -1)
return -2;
- if (start < 0 || end < 0) {
- PyErr_SetString(PyExc_IndexError, "string index out of range");
- return -2;
- }
- if (end > PyUnicode_GET_LENGTH(str))
- end = PyUnicode_GET_LENGTH(str);
- if (start >= end)
+ len = PyUnicode_GET_LENGTH(str);
+ ADJUST_INDICES(start, end, len);
+ if (end - start < 1)
return -1;
kind = PyUnicode_KIND(str);
result = findchar(PyUnicode_1BYTE_DATA(str) + kind*start,
« Lib/test/test_unicode.py ('K') | « Modules/_testcapimodule.c ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+