[Python-checkins] Add a warning message about PyOS_snprintf (GH-95993)

miss-islington webhook-mailer at python.org
Fri Oct 7 16:26:52 EDT 2022


https://github.com/python/cpython/commit/0a84b7aa4d89c9af7fa10dcb9943490669da4db6
commit: 0a84b7aa4d89c9af7fa10dcb9943490669da4db6
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-10-07T13:26:46-07:00
summary:

Add a warning message about PyOS_snprintf (GH-95993)

(cherry picked from commit c7b220499662f0c7a4cae51e33372f92ca7b1ee9)

Co-authored-by: Eric Wieser <wieser.eric at gmail.com>

files:
M Doc/c-api/conversion.rst
M Python/mysnprintf.c

diff --git a/Doc/c-api/conversion.rst b/Doc/c-api/conversion.rst
index 9b9c4ffa4d03..fdb321fe7ab3 100644
--- a/Doc/c-api/conversion.rst
+++ b/Doc/c-api/conversion.rst
@@ -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:
 
diff --git a/Python/mysnprintf.c b/Python/mysnprintf.c
index cd69198011e3..2a505d14f82c 100644
--- a/Python/mysnprintf.c
+++ b/Python/mysnprintf.c
@@ -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.
 



More information about the Python-checkins mailing list