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.
This commit is contained in:
Marc-André Lemburg 2004-11-22 13:02:31 +00:00
parent 6d60c09624
commit a9cadcd41b
4 changed files with 25 additions and 7 deletions

View file

@ -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;
}