diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Python/mysnprintf.c | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 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 25a8e26018..458ca14d5c 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 } |