summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-08 19:48:07 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-08 19:48:07 (GMT)
commit74a7e3b981265e4f742658b19bdac0818e364920 (patch)
treed653eb314dbbea3cedd4f311cf63dba30fcf1f16 /Objects
parent9ffb5d7828f87e620a5e1098fd2c4f9021a0bd3f (diff)
parent21d9f10c9442ba646340913beba8cf73cc77c885 (diff)
downloadcpython-74a7e3b981265e4f742658b19bdac0818e364920.zip
cpython-74a7e3b981265e4f742658b19bdac0818e364920.tar.gz
cpython-74a7e3b981265e4f742658b19bdac0818e364920.tar.bz2
Merge from 3.6.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 298cd23..b58cf02 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1549,15 +1549,19 @@ PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start,
if (PyUnicode_READY(to) == -1)
return -1;
- if (from_start < 0) {
+ if ((size_t)from_start > (size_t)PyUnicode_GET_LENGTH(from)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return -1;
}
- if (to_start < 0) {
+ if ((size_t)to_start > (size_t)PyUnicode_GET_LENGTH(to)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return -1;
}
- how_many = Py_MIN(PyUnicode_GET_LENGTH(from), how_many);
+ if (how_many < 0) {
+ PyErr_SetString(PyExc_SystemError, "how_many cannot be negative");
+ return -1;
+ }
+ how_many = Py_MIN(PyUnicode_GET_LENGTH(from)-from_start, how_many);
if (to_start + how_many > PyUnicode_GET_LENGTH(to)) {
PyErr_Format(PyExc_SystemError,
"Cannot write %zi characters at %zi "