-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-111089: PyUnicode_AsUTF8AndSize() sets size on error #111106
Conversation
See also PR #111100: Add tests for failing PyUnicode_AsUTF8AndSize() with psize=NULL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. See also #110865.
Doc/c-api/unicode.rst
Outdated
@@ -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 0 (if it's not NULL) and return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On error, set an exception, set *size* to 0 (if it's not NULL) and return | |
On error, set an exception, set *size* to ``0`` (if it's not ``NULL``) and return |
Why set size to 0, and not to -1? There is larger chance to miss error. For example |
On error, PyUnicode_AsUTF8AndSize() now sets the size argument to -1, to avoid undefined value.
585158d
to
ae7734d
Compare
That's a very good idea! I updated my PR to set size of -1 on error. I just picked 0 randomly. I forgot that size can be negative. |
Oh, tests failed with:
|
I failed to reproduce the Sphinx crash locally. And the test passed when run again. I merged my PR, thanks for review Serhiy. |
…#111106) On error, PyUnicode_AsUTF8AndSize() now sets the size argument to -1, to avoid undefined value.
…#111106) On error, PyUnicode_AsUTF8AndSize() now sets the size argument to -1, to avoid undefined value.
On error, PyUnicode_AsUTF8AndSize() now sets the size argument to 0, to avoid undefined value.
📚 Documentation preview 📚: https://cpython-previews--111106.org.readthedocs.build/