Commit 133d5856 authored by JP Dinger's avatar JP Dinger Committed by JP Dinger

sprintf +n in file.c, plus add and use vlc_num_keys and vlc_num_modifiers.

Signed-off-by: default avatarJP Dinger <jpd@videolan.org>
parent 224dccda
......@@ -108,6 +108,8 @@ static const struct key_descriptor_s vlc_modifiers[] =
{ "Meta", KEY_MODIFIER_META },
{ "Command", KEY_MODIFIER_COMMAND }
};
enum { vlc_num_modifiers=sizeof(vlc_modifiers)
/sizeof(struct key_descriptor_s) };
static const struct key_descriptor_s vlc_keys[] =
{
......@@ -221,11 +223,12 @@ static const struct key_descriptor_s vlc_keys[] =
{ "Media Stop", KEY_MEDIA_STOP },
{ "Media Play Pause", KEY_MEDIA_PLAY_PAUSE }
};
enum { vlc_num_keys=sizeof(vlc_keys)/sizeof(struct key_descriptor_s) };
static inline const char *KeyToString( int i_key )
{
unsigned int i = 0;
for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++ )
size_t i;
for ( i = 0; i < vlc_num_keys; ++i )
{
if ( vlc_keys[i].i_key_code == i_key )
{
......@@ -237,8 +240,8 @@ static inline const char *KeyToString( int i_key )
static inline int StringToKey( char *psz_key )
{
unsigned int i = 0;
for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++ )
size_t i;
for ( i = 0; i < vlc_num_keys; ++i )
{
if ( !strcmp( vlc_keys[i].psz_key_string, psz_key ))
{
......
......@@ -171,14 +171,11 @@ KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
int * py_pos )
: ConfigControl( p_this, p_item, parent, hInst )
{
// Number of keys descriptions
unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
// Init the keys decriptions array
if( m_keysList == NULL )
{
m_keysList = new string[i_keys];
for( unsigned int i = 0; i < i_keys; i++ )
m_keysList = new string[vlc_num_keys];
for( size_t i = 0; i < vlc_num_keys; ++i )
{
m_keysList[i] = vlc_keys[i].psz_key_string;
}
......@@ -233,7 +230,7 @@ KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
*py_pos += 15 + 10;
for( unsigned int i = 0; i < i_keys ; i++ )
for( size_t i = 0; i < vlc_num_keys ; ++i )
{
ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
......
......@@ -744,11 +744,11 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
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 ) ) )
......@@ -759,7 +759,7 @@ int ConfigStringToKey( const char *psz_key )
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 ) )
{
......@@ -772,7 +772,10 @@ int ConfigStringToKey( const char *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;
......@@ -783,20 +786,20 @@ char *ConfigKeyToString( int i_key )
*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;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment