From c93bca489dc84a58d8b6fa524b84a4722c02f714 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 14 Feb 2017 02:49:08 -0500 Subject: [PATCH] stdlib: Fixed crash on SDL_snprintf("%s", NULL). Like other C runtimes, it should probably produce the string "(null)". This bug probably only affected Windows, as most platforms use their standard C runtime's snprintf(). --- src/stdlib/SDL_string.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index d4712fab9..bc9d021d3 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -1313,6 +1313,10 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str size_t length = 0; size_t slen; + if (string == NULL) { + string = "(null)"; + } + if (info && info->width && (size_t)info->width > SDL_strlen(string)) { char fill = info->pad_zeroes ? '0' : ' '; size_t width = info->width - SDL_strlen(string);