summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-09-28 19:37:03 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-09-28 19:37:03 (GMT)
commitbe78eaf2de68acce390877b43fa829ef59b493f1 (patch)
tree845715bc9c2c4ca3589a037e9988374376f38bf8 /Include
parentfb5f5f24207ff18bab339561b4017b59ee3b3bc8 (diff)
downloadcpython-be78eaf2de68acce390877b43fa829ef59b493f1.zip
cpython-be78eaf2de68acce390877b43fa829ef59b493f1.tar.gz
cpython-be78eaf2de68acce390877b43fa829ef59b493f1.tar.bz2
PyUnicode_CopyCharacters() checks for buffer and character overflow
It now returns the number of written characters on success.
Diffstat (limited to 'Include')
-rw-r--r--Include/unicodeobject.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index b23f8a7..3538f1a 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -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,