Skip to content

Commit

Permalink
Add a warning message about PyOS_snprintf (#95993)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser authored Oct 7, 2022
1 parent d5fea01 commit c7b2204
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Doc/c-api/conversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ not.
The wrappers ensure that ``str[size-1]`` is always ``'\0'`` upon return. They
never write more than *size* bytes (including the trailing ``'\0'``) into str.
Both functions require that ``str != NULL``, ``size > 0``, ``format != NULL``
and ``size < INT_MAX``.
and ``size < INT_MAX``. Note that this means there is no equivalent to the C99
``n = snprintf(NULL, 0, ...)`` which would determine the necessary buffer size.
The return value (*rv*) for these functions should be interpreted as follows:
Expand Down
1 change: 1 addition & 0 deletions Python/mysnprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
would have been written had the buffer not been too small, and to set
the last byte of the buffer to \0. At least MS _vsnprintf returns a
negative value instead, and fills the entire buffer with non-\0 data.
Unlike C99, our wrappers do not support passing a null buffer.
The wrappers ensure that str[size-1] is always \0 upon return.
Expand Down

0 comments on commit c7b2204

Please sign in to comment.