From: Fredrik Lundh Date: Thu, 25 May 2006 15:49:45 +0000 (+0000) Subject: needforspeed: make new upper/lower work properly for single-character X-Git-Tag: v2.5b1~542 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b4e33ef14cecd0bc9c6566ea8b402733e7e445f;p=python needforspeed: make new upper/lower work properly for single-character strings too... (thanks to georg brandl for spotting the exact problem faster than anyone else) --- diff --git a/Objects/stringobject.c b/Objects/stringobject.c index d3ab54e214..3ec45243d2 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -2040,14 +2040,16 @@ string_lower(PyStringObject *self) Py_ssize_t i, n = PyString_GET_SIZE(self); PyObject *newobj; - newobj = PyString_FromStringAndSize(PyString_AS_STRING(self), n); + newobj = PyString_FromStringAndSize(NULL, n); if (!newobj) return NULL; s = PyString_AS_STRING(newobj); + memcpy(s, PyString_AS_STRING(self), n); + for (i = 0; i < n; i++) { - char c = Py_CHARMASK(s[i]); + int c = Py_CHARMASK(s[i]); if (isupper(c)) s[i] = _tolower(c); } @@ -2067,14 +2069,16 @@ string_upper(PyStringObject *self) Py_ssize_t i, n = PyString_GET_SIZE(self); PyObject *newobj; - newobj = PyString_FromStringAndSize(PyString_AS_STRING(self), n); + newobj = PyString_FromStringAndSize(NULL, n); if (!newobj) return NULL; s = PyString_AS_STRING(newobj); + memcpy(s, PyString_AS_STRING(self), n); + for (i = 0; i < n; i++) { - char c = Py_CHARMASK(s[i]); + int c = Py_CHARMASK(s[i]); if (islower(c)) s[i] = _toupper(c); }