Fixed crash if a game controller is disconnected while the connect message is in flight

main
Sam Lantinga 2022-09-22 22:50:28 -07:00
parent aa2e2f4843
commit 7312b93d32
1 changed files with 5 additions and 2 deletions

View File

@ -106,14 +106,17 @@ static void UpdateWindowTitle()
const char *name = SDL_GameControllerName(gamecontroller);
const char *serial = SDL_GameControllerGetSerial(gamecontroller);
const char *basetitle = "Game Controller Test: ";
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + (serial ? 3 + SDL_strlen(serial) : 0) + 1;
const size_t titlelen = SDL_strlen(basetitle) + (name ? SDL_strlen(name) : 0) + (serial ? 3 + SDL_strlen(serial) : 0) + 1;
char *title = (char *)SDL_malloc(titlelen);
retval = SDL_FALSE;
done = SDL_FALSE;
if (title) {
SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
SDL_strlcpy(title, basetitle, titlelen);
if (name) {
SDL_strlcat(title, name, titlelen);
}
if (serial) {
SDL_strlcat(title, " (", titlelen);
SDL_strlcat(title, serial, titlelen);