PyUnicode_CopyCharacters() checks for buffer and character overflow

It now returns the number of written characters on success.
This commit is contained in:
Victor Stinner 2011-09-28 21:37:03 +02:00
parent fb5f5f2420
commit be78eaf2de
2 changed files with 91 additions and 84 deletions

View file

@ -519,10 +519,22 @@ PyAPI_FUNC(int) _PyUnicode_Ready(
#endif
/* Copy character from one unicode object into another, this function performs
character conversion when nessesary and falls back to memcpy if possible.
Return -1 and raise an exception on error, return 0 on success. */
character conversion when necessary and falls back to memcpy if possible.
Fail if 'to' is smaller than how_many or smaller than len(from)-from_start,
or if kind(from[from_start:from_start+how_many]) > kind(to).
Return the number of written character, or return -1 and raise an exception
on error.
Pseudo-code:
how_many = min(how_many, len(from) - from_start)
to[to_start:to_start+how_many] = from[from_start:from_start+how_many]
return how_many
*/
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyUnicode_CopyCharacters(
PyAPI_FUNC(Py_ssize_t) PyUnicode_CopyCharacters(
PyObject *to,
Py_ssize_t to_start,
PyObject *from,