Uh oh!
There was an error while loading. Please reload this page.
gh-111089: PyUnicode_AsUTF8AndSize() sets size on error - #111106
Conversation
vstinner
commented
Oct 20, 2023
See also PR #111100: Add tests for failing PyUnicode_AsUTF8AndSize() with psize=NULL. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM. See also #110865.
| 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.
| 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 |
serhiy-storchaka
commented
Oct 20, 2023
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.
vstinner
commented
Oct 20, 2023
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. |
vstinner
commented
Oct 20, 2023
Oh, tests failed with: |
vstinner
commented
Oct 20, 2023
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/