Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
This commit is contained in:
parent
2e9dea31c5
commit
4cec546dca
1 changed files with 33 additions and 23 deletions
|
@ -518,11 +518,18 @@ char *SDL_PrivateGetControllerGUIDFromMappingString( const char *pMapping )
|
||||||
*/
|
*/
|
||||||
char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping )
|
char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping )
|
||||||
{
|
{
|
||||||
const char *pFirstComma = SDL_strchr( pMapping, ',' );
|
const char *pFirstComma, *pSecondComma;
|
||||||
const char *pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
|
char *pchName;
|
||||||
if ( pFirstComma && pSecondComma )
|
|
||||||
{
|
pFirstComma = SDL_strchr( pMapping, ',' );
|
||||||
char *pchName = SDL_malloc( pSecondComma - pFirstComma );
|
if ( !pFirstComma )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
|
||||||
|
if ( !pSecondComma )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
pchName = SDL_malloc( pSecondComma - pFirstComma );
|
||||||
if ( !pchName )
|
if ( !pchName )
|
||||||
{
|
{
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
|
@ -532,8 +539,6 @@ char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping )
|
||||||
pchName[ pSecondComma - pFirstComma - 1 ] = 0;
|
pchName[ pSecondComma - pFirstComma - 1 ] = 0;
|
||||||
return pchName;
|
return pchName;
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -541,12 +546,17 @@ char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping )
|
||||||
*/
|
*/
|
||||||
const char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping )
|
const char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping )
|
||||||
{
|
{
|
||||||
const char *pFirstComma = SDL_strchr( pMapping, ',' );
|
const char *pFirstComma, *pSecondComma;
|
||||||
const char *pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
|
|
||||||
if ( pSecondComma )
|
pFirstComma = SDL_strchr( pMapping, ',' );
|
||||||
return pSecondComma + 1; // mapping is everything after the 3rd comma, no need to malloc it
|
if ( !pFirstComma )
|
||||||
else
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
|
||||||
|
if ( !pSecondComma )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return pSecondComma + 1; /* mapping is everything after the 3rd comma, no need to malloc it */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -603,8 +613,8 @@ SDL_GameControllerInit(void)
|
||||||
if ( hint && hint[0] )
|
if ( hint && hint[0] )
|
||||||
{
|
{
|
||||||
int nchHints = SDL_strlen( hint );
|
int nchHints = SDL_strlen( hint );
|
||||||
char *pUserMappings = SDL_malloc( nchHints + 1 );
|
char *pUserMappings = SDL_malloc( nchHints + 1 ); /* FIXME: memory leak, but we can't free it in this function because pchMapping below points into this memory */
|
||||||
SDL_memcpy( pUserMappings, hint, nchHints );
|
SDL_memcpy( pUserMappings, hint, nchHints + 1 );
|
||||||
while ( pUserMappings )
|
while ( pUserMappings )
|
||||||
{
|
{
|
||||||
char *pchGUID;
|
char *pchGUID;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue