Minor sanity checking and tweaks in SDL_JoystickGetGUIDString().
authorRyan C. Gordon
Tue, 11 Dec 2012 18:46:09 -0500
changeset 674880a6aac67ad9
parent 6747 b617821795bf
child 6749 87254cb5734f
Minor sanity checking and tweaks in SDL_JoystickGetGUIDString().
src/joystick/SDL_joystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Tue Dec 11 16:53:59 2012 -0500
     1.2 +++ b/src/joystick/SDL_joystick.c	Tue Dec 11 18:46:09 2012 -0500
     1.3 @@ -698,22 +698,22 @@
     1.4  void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID )
     1.5  {
     1.6  	static const char k_rgchHexToASCII[] = "0123456789abcdef";
     1.7 -	char *pchOut = NULL;
     1.8 -	char *pchString = NULL;
     1.9  	int i;
    1.10 -	
    1.11 -	pchOut = pszGUID;
    1.12  
    1.13 -	for ( i = 0; i < sizeof(guid) && i < (cbGUID-1); i++ )
    1.14 +    if ((pszGUID == NULL) || (cbGUID <= 0)) {
    1.15 +        return;
    1.16 +    }
    1.17 +
    1.18 +	for ( i = 0; i < sizeof(guid.data) && i < (cbGUID-1); i++ )
    1.19  	{
    1.20  		// each input byte writes 2 ascii chars, and might write a null byte.
    1.21  		// If we don't have room for next input byte, stop
    1.22  		unsigned char c = guid.data[i];
    1.23  
    1.24 -		*pchOut++ = k_rgchHexToASCII[ c >> 4 ];
    1.25 -		*pchOut++ = k_rgchHexToASCII[ c & 0x0F ];
    1.26 +		*pszGUID++ = k_rgchHexToASCII[ c >> 4 ];
    1.27 +		*pszGUID++ = k_rgchHexToASCII[ c & 0x0F ];
    1.28  	}
    1.29 -	*pchOut = '\0';
    1.30 +	*pszGUID = '\0';
    1.31  }
    1.32  
    1.33