summaryrefslogtreecommitdiffstats
path: root/Objects
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 /Objects
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 'Objects')
-rw-r--r--Objects/unicodeobject.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 48821bd..5e5dac5 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -384,8 +384,11 @@ int PyUnicode_AsWideChar(PyUnicodeObject *unicode,
PyErr_BadInternalCall();
return -1;
}
+
+ /* If possible, try to copy the 0-termination as well */
if (size > PyUnicode_GET_SIZE(unicode))
- size = PyUnicode_GET_SIZE(unicode);
+ size = PyUnicode_GET_SIZE(unicode) + 1;
+
#ifdef HAVE_USABLE_WCHAR_T
memcpy(w, unicode->str, size * sizeof(wchar_t));
#else
@@ -398,6 +401,9 @@ int PyUnicode_AsWideChar(PyUnicodeObject *unicode,
}
#endif
+ if (size > PyUnicode_GET_SIZE(unicode))
+ return PyUnicode_GET_SIZE(unicode);
+ else
return size;
}