diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/tools/python3/src/Python/mysnprintf.c | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Python/mysnprintf.c')
-rw-r--r-- | contrib/tools/python3/src/Python/mysnprintf.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/contrib/tools/python3/src/Python/mysnprintf.c b/contrib/tools/python3/src/Python/mysnprintf.c index 458ca14d5c..25a8e26018 100644 --- a/contrib/tools/python3/src/Python/mysnprintf.c +++ b/contrib/tools/python3/src/Python/mysnprintf.c @@ -1,8 +1,8 @@ #include "Python.h" -/* snprintf() and vsnprintf() wrappers. - - If the platform has vsnprintf, we use it, else we +/* snprintf() and vsnprintf() wrappers. + + If the platform has vsnprintf, we use it, else we emulate it in a half-hearted way. Even if the platform has it, we wrap it because platforms differ in what vsnprintf does in case the buffer is too small: C99 behavior is to return the number of characters that @@ -54,15 +54,15 @@ PyOS_snprintf(char *str, size_t size, const char *format, ...) int PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) { - assert(str != NULL); - assert(size > 0); - assert(format != NULL); - + assert(str != NULL); + assert(size > 0); + assert(format != NULL); + int len; /* # bytes written, excluding \0 */ -#if defined(_MSC_VER) || defined(HAVE_SNPRINTF) -# define _PyOS_vsnprintf_EXTRA_SPACE 1 +#if defined(_MSC_VER) || defined(HAVE_SNPRINTF) +# define _PyOS_vsnprintf_EXTRA_SPACE 1 #else -# define _PyOS_vsnprintf_EXTRA_SPACE 512 +# define _PyOS_vsnprintf_EXTRA_SPACE 512 char *buffer; #endif /* We take a size_t as input but return an int. Sanity check @@ -73,12 +73,12 @@ PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) goto Done; } -#if defined(_MSC_VER) - len = _vsnprintf(str, size, format, va); -#elif defined(HAVE_SNPRINTF) +#if defined(_MSC_VER) + len = _vsnprintf(str, size, format, va); +#elif defined(HAVE_SNPRINTF) len = vsnprintf(str, size, format, va); #else - /* Emulate vsnprintf(). */ + /* Emulate vsnprintf(). */ buffer = PyMem_MALLOC(size + _PyOS_vsnprintf_EXTRA_SPACE); if (buffer == NULL) { len = -666; @@ -86,12 +86,12 @@ PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) } len = vsprintf(buffer, format, va); - if (len < 0) { + if (len < 0) { /* ignore the error */; - } - else if ((size_t)len >= size + _PyOS_vsnprintf_EXTRA_SPACE) { - _Py_FatalErrorFunc(__func__, "Buffer overflow"); - } + } + else if ((size_t)len >= size + _PyOS_vsnprintf_EXTRA_SPACE) { + _Py_FatalErrorFunc(__func__, "Buffer overflow"); + } else { const size_t to_copy = (size_t)len < size ? (size_t)len : size - 1; @@ -101,11 +101,11 @@ PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) } PyMem_FREE(buffer); #endif - + Done: - if (size > 0) { + if (size > 0) { str[size-1] = '\0'; - } + } return len; #undef _PyOS_vsnprintf_EXTRA_SPACE } |