summaryrefslogtreecommitdiffstats
path: root/Modules/_localemodule.c
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2004-11-22 13:02:31 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2004-11-22 13:02:31 (GMT)
commita9cadcd41b27fd045626c4e3b98315aaa257ca75 (patch)
treede54d0594b72a0b5fbdd6eaecd28a47837597d02 /Modules/_localemodule.c
parent6d60c0962444bb8f6d13208489095144e7752924 (diff)
downloadcpython-a9cadcd41b27fd045626c4e3b98315aaa257ca75.zip
cpython-a9cadcd41b27fd045626c4e3b98315aaa257ca75.tar.gz
cpython-a9cadcd41b27fd045626c4e3b98315aaa257ca75.tar.bz2
Correct the handling of 0-termination of PyUnicode_AsWideChar()
and its usage in PyLocale_strcoll(). Clarify the documentation on this. Thanks to Andreas Degert for pointing this out.
Diffstat (limited to 'Modules/_localemodule.c')
-rw-r--r--Modules/_localemodule.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 3e3df22..de470e0 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -305,7 +305,6 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
}
/* Convert the unicode strings to wchar[]. */
len1 = PyUnicode_GET_SIZE(os1) + 1;
- len2 = PyUnicode_GET_SIZE(os2) + 1;
ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t));
if (!ws1) {
PyErr_NoMemory();
@@ -313,6 +312,8 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
}
if (PyUnicode_AsWideChar((PyUnicodeObject*)os1, ws1, len1) == -1)
goto done;
+ ws1[len1 - 1] = 0;
+ len2 = PyUnicode_GET_SIZE(os2) + 1;
ws2 = PyMem_MALLOC(len2 * sizeof(wchar_t));
if (!ws2) {
PyErr_NoMemory();
@@ -320,6 +321,7 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
}
if (PyUnicode_AsWideChar((PyUnicodeObject*)os2, ws2, len2) == -1)
goto done;
+ ws2[len2 - 1] = 0;
/* Collate the strings. */
result = PyInt_FromLong(wcscoll(ws1, ws2));
done: