From f487d63a6b4b1d18cbbafde5d99b0c32e377a96c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 3 Dec 2020 18:16:56 -0800 Subject: [PATCH] Fixed crash when printing NULL wide character string --- src/stdlib/SDL_string.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 766f8cf9d..44f34601d 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1899,10 +1899,15 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, { /* In practice this is used on Windows for WCHAR strings */ wchar_t *wide_arg = va_arg(ap, wchar_t *); - char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg)); - info.pad_zeroes = SDL_FALSE; - len = SDL_PrintString(text, left, &info, arg); - SDL_free(arg); + if (wide_arg) { + char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg)); + info.pad_zeroes = SDL_FALSE; + len = SDL_PrintString(text, left, &info, arg); + SDL_free(arg); + } else { + info.pad_zeroes = SDL_FALSE; + len = SDL_PrintString(text, left, &info, NULL); + } done = SDL_TRUE; } break;