From: Victor Stinner Date: Sun, 23 Oct 2011 18:10:08 +0000 (+0200) Subject: PyUnicode_AsUnicodeCopy() uses PyUnicode_AsUnicodeAndSize() to get directly the length X-Git-Tag: v3.3.0a1~1031 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=57ffa9d4ffcb4af84a6367a0a259b67333b33952;p=thirdparty%2FPython%2Fcpython.git PyUnicode_AsUnicodeCopy() uses PyUnicode_AsUnicodeAndSize() to get directly the length --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index aedcec53c7ba..6c73779328c1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14210,21 +14210,21 @@ Py_UNICODE* PyUnicode_AsUnicodeCopy(PyObject *unicode) { Py_UNICODE *u, *copy; - Py_ssize_t size; + Py_ssize_t len, size; if (!PyUnicode_Check(unicode)) { PyErr_BadArgument(); return NULL; } - u = PyUnicode_AsUnicode(unicode); + u = PyUnicode_AsUnicodeAndSize(unicode, &len); if (u == NULL) return NULL; /* Ensure we won't overflow the size. */ - if (PyUnicode_GET_SIZE(unicode) > ((PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) - 1)) { + if (len > ((PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) - 1)) { PyErr_NoMemory(); return NULL; } - size = PyUnicode_GET_SIZE(unicode) + 1; /* copy the nul character */ + size = len + 1; /* copy the null character */ size *= sizeof(Py_UNICODE); copy = PyMem_Malloc(size); if (copy == NULL) {