From: Andrii Simiklit <andrii.simik...@globallogic.com> The win '_vsnprintf' function incompatibility with C99 vsnprintf. At least for case when the input buffer size less than the required size: '_vsnprintf' returns -1 for this case. 'vsnprintf' returns the required size.
So use cross platform implementation 'util_vsnprintf'. v5: subject was updated from 'mesa/util: ...' to 'util: ...' Reviewed-by: Emil Velikov <emil.veli...@collabora.com> Signed-off-by: Andrii Simiklit <andrii.simik...@globallogic.com> --- src/util/ralloc.c | 25 ++++++------------------- src/util/u_string.h | 5 +++++ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/util/ralloc.c b/src/util/ralloc.c index 5d77f75..798560f 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -28,13 +28,8 @@ #include <string.h> #include <stdint.h> -/* Some versions of MinGW are missing _vscprintf's declaration, although they - * still provide the symbol in the import library. */ -#ifdef __MINGW32__ -_CRTIMP int _vscprintf(const char *format, va_list argptr); -#endif - #include "ralloc.h" +#include "u_string.h" #ifndef va_copy #ifdef __va_copy @@ -448,15 +443,7 @@ printf_length(const char *fmt, va_list untouched_args) va_list args; va_copy(args, untouched_args); -#ifdef _WIN32 - /* We need to use _vcsprintf to calculate the size as vsnprintf returns -1 - * if the number of characters to write is greater than count. - */ - size = _vscprintf(fmt, args); - (void)junk; -#else - size = vsnprintf(&junk, 1, fmt, args); -#endif + size = util_vsnprintf(&junk, 1, fmt, args); assert(size >= 0); va_end(args); @@ -471,7 +458,7 @@ ralloc_vasprintf(const void *ctx, const char *fmt, va_list args) char *ptr = ralloc_size(ctx, size); if (ptr != NULL) - vsnprintf(ptr, size, fmt, args); + util_vsnprintf(ptr, size, fmt, args); return ptr; } @@ -529,7 +516,7 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt, if (unlikely(ptr == NULL)) return false; - vsnprintf(ptr + *start, new_length + 1, fmt, args); + util_vsnprintf(ptr + *start, new_length + 1, fmt, args); *str = ptr; *start += new_length; return true; @@ -804,7 +791,7 @@ linear_vasprintf(void *parent, const char *fmt, va_list args) char *ptr = linear_alloc_child(parent, size); if (ptr != NULL) - vsnprintf(ptr, size, fmt, args); + util_vsnprintf(ptr, size, fmt, args); return ptr; } @@ -862,7 +849,7 @@ linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start, if (unlikely(ptr == NULL)) return false; - vsnprintf(ptr + *start, new_length + 1, fmt, args); + util_vsnprintf(ptr + *start, new_length + 1, fmt, args); *str = ptr; *start += new_length; return true; diff --git a/src/util/u_string.h b/src/util/u_string.h index ca65623..81a7b0f 100644 --- a/src/util/u_string.h +++ b/src/util/u_string.h @@ -67,6 +67,11 @@ util_strchrnul(const char *s, char c) #endif #ifdef _WIN32 +/* Some versions of MinGW are missing _vscprintf's declaration, although they + * still provide the symbol in the import library. */ +#ifdef __MINGW32__ +_CRTIMP int _vscprintf(const char *format, va_list argptr); +#endif static inline int util_vsnprintf(char *str, size_t size, const char *format, va_list ap) -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev