int ConfigStringToKey( const char *psz_key )
{
int i_key = 0;
- unsigned int i;
+ size_t i;
const char *psz_parser = strchr( psz_key, '-' );
while( psz_parser && psz_parser != psz_key )
{
- for( i = 0; i < sizeof(vlc_modifiers) / sizeof(key_descriptor_t); i++ )
+ for( i = 0; i < vlc_num_modifiers; ++i )
{
if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,
strlen( vlc_modifiers[i].psz_key_string ) ) )
psz_key = psz_parser + 1;
psz_parser = strchr( psz_key, '-' );
}
- for( i = 0; i < sizeof(vlc_keys) / sizeof( key_descriptor_t ); i++ )
+ for( i = 0; i < vlc_num_keys; ++i )
{
if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )
{
char *ConfigKeyToString( int i_key )
{
- char *psz_key = malloc( 100 );
+ // Worst case appears to be 45 characters:
+ // "Command-Meta-Ctrl-Shift-Alt-Browser Favorites"
+ enum { keylen=64 };
+ char *psz_key = malloc( keylen );
char *p;
size_t index;
*psz_key = '\0';
p = psz_key;
- for( index = 0; index < (sizeof(vlc_modifiers) / sizeof(key_descriptor_t));
- index++ )
+ for( index = 0; index < vlc_num_modifiers; ++index )
{
if( i_key & vlc_modifiers[index].i_key_code )
{
- p += sprintf( p, "%s-", vlc_modifiers[index].psz_key_string );
+ p += snprintf( p, keylen-(psz_key-p), "%s-",
+ vlc_modifiers[index].psz_key_string );
}
}
- for( index = 0; index < (sizeof(vlc_keys) / sizeof( key_descriptor_t));
- index++)
+ for( index = 0; index < vlc_num_keys; ++index )
{
if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )
{
- p += sprintf( p, "%s", vlc_keys[index].psz_key_string );
+ p += snprintf( p, keylen-(psz_key-p), "%s",
+ vlc_keys[index].psz_key_string );
break;
}
}