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

Side by Side Diff: Objects/unicodeobject.c

Issue 28822: Fix indices handling in PyUnicode_FindChar
Patch Set: Created 2 years, 9 months ago
Left:
Right:
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 unified diff | Download patch
« Lib/test/test_unicode.py ('K') | « Modules/_testcapimodule.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 2
3 Unicode implementation based on original code by Fredrik Lundh, 3 Unicode implementation based on original code by Fredrik Lundh,
4 modified by Marc-Andre Lemburg <mal@lemburg.com>. 4 modified by Marc-Andre Lemburg <mal@lemburg.com>.
5 5
6 Major speed upgrades to the method implementations at the Reykjavik 6 Major speed upgrades to the method implementations at the Reykjavik
7 NeedForSpeed sprint, by Fredrik Lundh and Andrew Dalke. 7 NeedForSpeed sprint, by Fredrik Lundh and Andrew Dalke.
8 8
9 Copyright (c) Corporation for National Research Initiatives. 9 Copyright (c) Corporation for National Research Initiatives.
10 10
(...skipping 9443 matching lines...) Expand 10 before | Expand all | Expand 10 after
9454 9454
9455 return any_find_slice(str, substr, start, end, direction); 9455 return any_find_slice(str, substr, start, end, direction);
9456 } 9456 }
9457 9457
9458 Py_ssize_t 9458 Py_ssize_t
9459 PyUnicode_FindChar(PyObject *str, Py_UCS4 ch, 9459 PyUnicode_FindChar(PyObject *str, Py_UCS4 ch,
9460 Py_ssize_t start, Py_ssize_t end, 9460 Py_ssize_t start, Py_ssize_t end,
9461 int direction) 9461 int direction)
9462 { 9462 {
9463 int kind; 9463 int kind;
9464 Py_ssize_t result; 9464 Py_ssize_t len, result;
9465 if (PyUnicode_READY(str) == -1) 9465 if (PyUnicode_READY(str) == -1)
9466 return -2; 9466 return -2;
9467 if (start < 0 || end < 0) { 9467 len = PyUnicode_GET_LENGTH(str);
9468 PyErr_SetString(PyExc_IndexError, "string index out of range"); 9468 ADJUST_INDICES(start, end, len);
9469 return -2; 9469 if (end - start < 1)
9470 }
9471 if (end > PyUnicode_GET_LENGTH(str))
9472 end = PyUnicode_GET_LENGTH(str);
9473 if (start >= end)
9474 return -1; 9470 return -1;
9475 kind = PyUnicode_KIND(str); 9471 kind = PyUnicode_KIND(str);
9476 result = findchar(PyUnicode_1BYTE_DATA(str) + kind*start, 9472 result = findchar(PyUnicode_1BYTE_DATA(str) + kind*start,
9477 kind, end-start, ch, direction); 9473 kind, end-start, ch, direction);
9478 if (result == -1) 9474 if (result == -1)
9479 return -1; 9475 return -1;
9480 else 9476 else
9481 return start + result; 9477 return start + result;
9482 } 9478 }
9483 9479
(...skipping 6061 matching lines...) Expand 10 before | Expand all | Expand 10 after
15545 PyMODINIT_FUNC 15541 PyMODINIT_FUNC
15546 PyInit__string(void) 15542 PyInit__string(void)
15547 { 15543 {
15548 return PyModule_Create(&_string_module); 15544 return PyModule_Create(&_string_module);
15549 } 15545 }
15550 15546
15551 15547
15552 #ifdef __cplusplus 15548 #ifdef __cplusplus
15553 } 15549 }
15554 #endif 15550 #endif
OLDNEW
« 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+