[vlc-commits] Fix title N variable formatting
Rémi Denis-Courmont
git at videolan.org
Sat May 23 18:29:50 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat May 23 19:08:27 2015 +0300| [9f85beeeaa0d1d8e70854ed337f2fc46092b9934] | committer: Rémi Denis-Courmont
Fix title N variable formatting
Do not assume the title number is small; allocate large enough buffer.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9f85beeeaa0d1d8e70854ed337f2fc46092b9934
---
lib/media_player.c | 12 ++++--------
lib/video.c | 4 ++--
modules/gui/qt4/menus.cpp | 8 ++++----
src/input/event.c | 6 +++---
src/input/var.c | 9 ++++-----
5 files changed, 17 insertions(+), 22 deletions(-)
diff --git a/lib/media_player.c b/lib/media_player.c
index 2e9d19a..aa12901 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -1266,19 +1266,15 @@ int libvlc_media_player_get_chapter_count_for_title(
libvlc_media_player_t *p_mi,
int i_title )
{
- input_thread_t *p_input_thread;
vlc_value_t val;
- p_input_thread = libvlc_get_input_thread ( p_mi );
+ input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
if( !p_input_thread )
return -1;
- char *psz_name;
- if( asprintf( &psz_name, "title %2i", i_title ) == -1 )
- {
- vlc_object_release( p_input_thread );
- return -1;
- }
+ char psz_name[sizeof ("title ") + 3 * sizeof (int)];
+ sprintf( psz_name, "title %2u", i_title );
+
int i_ret = var_Change( p_input_thread, psz_name, VLC_VAR_CHOICESCOUNT, &val, NULL );
vlc_object_release( p_input_thread );
free( psz_name );
diff --git a/lib/video.c b/lib/video.c
index 9a9adeb..b2c9b34 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -405,8 +405,8 @@ libvlc_track_description_t *
libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
int i_title )
{
- char psz_title[12];
- sprintf( psz_title, "title %2i", i_title );
+ char psz_title[sizeof ("title ") + 3 * sizeof (int)];
+ sprintf( psz_title, "title %2u", i_title );
return libvlc_get_track_description( p_mi, psz_title );
}
diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index 29662f8..8916130 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -1354,15 +1354,15 @@ void VLCMenuBar::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
#undef TEXT_OR_VAR
/** HACK for the navigation submenu:
- * "title %2i" variables take the value 0 if not set
+ * "title %2u" variables take the value 0 if not set
*/
static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
{
- int i_title = 0;
- if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
+ unsigned i_title = 0;
+ if( sscanf( psz_var, "title %2u", &i_title ) <= 0 )
return true;
- int i_current_title = var_GetInteger( p_object, "title" );
+ unsigned i_current_title = var_GetInteger( p_object, "title" );
return ( i_title == i_current_title );
}
diff --git a/src/input/event.c b/src/input/event.c
index 5861f1f..d2d6301 100644
--- a/src/input/event.c
+++ b/src/input/event.c
@@ -149,9 +149,9 @@ void input_SendEventSeekpoint( input_thread_t *p_input, int i_title, int i_seekp
val.i_int = i_seekpoint;
var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
- /* "title %2i" */
- char psz_title[10];
- snprintf( psz_title, sizeof(psz_title), "title %2i", i_title );
+ /* "title %2u" */
+ char psz_title[sizeof ("title ") + 3 * sizeof (int)];
+ sprintf( psz_title, "title %2u", i_title );
var_Change( p_input, psz_title, VLC_VAR_SETVALUE, &val, NULL );
/* */
diff --git a/src/input/var.c b/src/input/var.c
index ac0e630..47f4b88 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -235,15 +235,14 @@ void input_ControlVarStop( input_thread_t *p_input )
if( p_input->p->i_title > 0 )
{
- char name[sizeof("title ") + 5 ];
- int i;
-
InputDelCallbacks( p_input, p_input_navigation_callbacks );
InputDelCallbacks( p_input, p_input_title_callbacks );
- for( i = 0; i < p_input->p->i_title; i++ )
+ for( int i = 0; i < p_input->p->i_title; i++ )
{
- snprintf( name, sizeof(name), "title %2i", i );
+ char name[sizeof("title ") + 3 * sizeof (int)];
+
+ sprintf( name, "title %2u", i );
var_DelCallback( p_input, name, NavigationCallback, (void *)(intptr_t)i );
}
}
More information about the vlc-commits
mailing list