Skip to content

Commit

Permalink
stdlib: Fixed crash on SDL_snprintf("%s", NULL).
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
icculus committed Feb 14, 2017
1 parent d1eb2d1 commit c93bca4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/stdlib/SDL_string.c
Expand Up @@ -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);
Expand Down

0 comments on commit c93bca4

Please sign in to comment.