gh-111089: PyUnicode_AsUTF8AndSize() sets size on error (#111106)

On error, PyUnicode_AsUTF8AndSize() now sets the size argument to -1,
to avoid undefined value.
This commit is contained in:
Victor Stinner 2023-10-20 20:03:11 +02:00 committed by GitHub
parent d8f32be5b6
commit f1e751e933
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View file

@ -971,8 +971,8 @@ These are the UTF-8 codec APIs:
returned buffer always has an extra null byte appended (not included in
*size*), regardless of whether there are any other null code points.
In the case of an error, ``NULL`` is returned with an exception set and no
*size* is stored.
On error, set an exception, set *size* to ``-1`` (if it's not NULL) and
return ``NULL``.
This caches the UTF-8 representation of the string in the Unicode object, and
subsequent calls will return a pointer to the same buffer. The caller is not