Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 17273:536cc126fb9f 2.0
- #122162 -- unicodeobject.c --- Fix unicode .split() off-by-one
- Loosely based on patch #103249 -- Fix core dumps in PyUnicode_Count
| author | Moshe Zadka <moshez@math.huji.ac.il> |
|---|---|
| date | Sat, 31 Mar 2001 06:48:52 +0000 |
| parents | 42b1a699a5dd |
| children |
line wrap: on
line diff
--- a/Objects/stringobject.c Fri Mar 30 21:01:09 2001 +0000 +++ b/Objects/stringobject.c Sat Mar 31 06:48:52 2001 +0000 @@ -1236,9 +1236,14 @@ sub = PyString_AS_STRING(subobj); n = PyString_GET_SIZE(subobj); } - else if (PyUnicode_Check(subobj)) - return PyInt_FromLong( - PyUnicode_Count((PyObject *)self, subobj, i, last)); + else if (PyUnicode_Check(subobj)) { + int count; + count = PyUnicode_Count((PyObject *)self, subobj, i, last); + if (count == -1) + return NULL; + else + return PyInt_FromLong((long) count); + } else if (PyObject_AsCharBuffer(subobj, &sub, &n)) return NULL; @@ -1637,10 +1642,15 @@ prefix = PyString_AS_STRING(subobj); plen = PyString_GET_SIZE(subobj); } - else if (PyUnicode_Check(subobj)) - return PyInt_FromLong( - PyUnicode_Tailmatch((PyObject *)self, - subobj, start, end, -1)); + else if (PyUnicode_Check(subobj)) { + int rc; + rc = PyUnicode_Tailmatch((PyObject *)self, + subobj, start, end, -1); + if (rc == -1) + return NULL; + else + return PyInt_FromLong((long) rc); + } else if (PyObject_AsCharBuffer(subobj, &prefix, &plen)) return NULL; @@ -1690,10 +1700,15 @@ suffix = PyString_AS_STRING(subobj); slen = PyString_GET_SIZE(subobj); } - else if (PyUnicode_Check(subobj)) - return PyInt_FromLong( - PyUnicode_Tailmatch((PyObject *)self, - subobj, start, end, +1)); + else if (PyUnicode_Check(subobj)) { + int rc; + rc = PyUnicode_Tailmatch((PyObject *)self, + subobj, start, end, +1); + if (rc == -1) + return NULL; + else + return PyInt_FromLong((long) rc); + } else if (PyObject_AsCharBuffer(subobj, &suffix, &slen)) return NULL;
