diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2022-10-07 18:49:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-07 18:49:53 (GMT) |
commit | c7b220499662f0c7a4cae51e33372f92ca7b1ee9 (patch) | |
tree | 492d6fd661848364fdedc9fa8060e5f8338ab8d3 | |
parent | d5fea01d9d439b1638cd8e5db19c33909841d86f (diff) | |
download | cpython-c7b220499662f0c7a4cae51e33372f92ca7b1ee9.zip cpython-c7b220499662f0c7a4cae51e33372f92ca7b1ee9.tar.gz cpython-c7b220499662f0c7a4cae51e33372f92ca7b1ee9.tar.bz2 |
Add a warning message about PyOS_snprintf (#95993)
-rw-r--r-- | Doc/c-api/conversion.rst | 3 | ||||
-rw-r--r-- | Python/mysnprintf.c | 1 |
2 files changed, 3 insertions, 1 deletions
diff --git a/Doc/c-api/conversion.rst b/Doc/c-api/conversion.rst index 9b9c4ff..fdb321f 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 cd69198..2a505d1 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. |