[vlc-commits] Remove variable name clashes in TAB_REMOVE

Rafaël Carré git at videolan.org
Wed Feb 6 19:35:55 CET 2013


vlc/vlc-2.0 | branch: master | Rafaël Carré <funman at videolan.org> | Mon Dec 17 01:00:29 2012 +0100| [6be4754f2f13d4b56a21634d481cdd2c73d0a974] | committer: Rémi Denis-Courmont

Remove variable name clashes in TAB_REMOVE

If foo[i] or bar[i_index] are used in TAB_REMOVE / TAB_FIND, they will
use another variable with local scope declared inside the macro.

for (int i = 0; i < 1; i++) {
    TAB_REMOVE( count, array, foo[i] );
}

will expand to:

for (int i = 0; i < 1; i++) {
    int i_index;
    .....
    for (int i = 0; i < count; i++)
        if (array[i] == foo[i])
        {
            index = i;
            break;
        }
    .....
}

And inner scope i is used to index foo, instead of the outer scope i
which we would expect without knowing the content of the macro.
(cherry picked from commit 728ef39d15cdbfc5b1bc9beba8a97493ef6c08fc)

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=6be4754f2f13d4b56a21634d481cdd2c73d0a974
---

 modules/demux/ts.c   |   11 ++++++-----
 modules/misc/rtsp.c  |    5 +++--
 src/input/vlmshell.c |    8 +++-----
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/modules/demux/ts.c b/modules/demux/ts.c
index 5628e35..82bdba4 100644
--- a/modules/demux/ts.c
+++ b/modules/demux/ts.c
@@ -4454,16 +4454,17 @@ static void PATCallBack( demux_t *p_demux, dvbpsi_pat_t *p_pat )
         /* Delete PMT pid */
         for( int i = 0; i < i_pmt_rm; i++ )
         {
-            SetPIDFilter( p_demux, pmt_rm[i]->i_pid, false );
+            ts_pid_t *pid = pmt_rm[i];
+            SetPIDFilter( p_demux, pid->i_pid, false );
 
-            for( int i_prg = 0; i_prg < pmt_rm[i]->psi->i_prg; i_prg++ )
+            for( int i_prg = 0; i_prg < pid->psi->i_prg; i_prg++ )
             {
-                const int i_number = pmt_rm[i]->psi->prg[i_prg]->i_number;
+                const int i_number = pid->psi->prg[i_prg]->i_number;
                 es_out_Control( p_demux->out, ES_OUT_DEL_GROUP, i_number );
             }
 
-            PIDClean( p_demux, &p_sys->pid[pmt_rm[i]->i_pid] );
-            TAB_REMOVE( p_sys->i_pmt, p_sys->pmt, pmt_rm[i] );
+            PIDClean( p_demux, &p_sys->pid[pid->i_pid] );
+            TAB_REMOVE( p_sys->i_pmt, p_sys->pmt, pid );
         }
 
         free( pmt_rm );
diff --git a/modules/misc/rtsp.c b/modules/misc/rtsp.c
index d7eaf13..37d8758 100644
--- a/modules/misc/rtsp.c
+++ b/modules/misc/rtsp.c
@@ -1441,9 +1441,10 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
 
             for( int i = 0; i < p_rtsp->i_es; i++ )
             {
-                if( p_rtsp->es[i]->p_media_es == p_es )
+                rtsp_client_es_t *es = p_rtsp->es[i];
+                if( es->p_media_es == p_es )
                 {
-                    TAB_REMOVE( p_rtsp->i_es, p_rtsp->es, p_rtsp->es[i] );
+                    TAB_REMOVE( p_rtsp->i_es, p_rtsp->es, es );
                     break;
                 }
             }
diff --git a/src/input/vlmshell.c b/src/input/vlmshell.c
index dd55037..0b9082f 100644
--- a/src/input/vlmshell.c
+++ b/src/input/vlmshell.c
@@ -702,13 +702,11 @@ static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
         }
         else if( !strcmp( psz_option, "inputdeln" ) )
         {
-            int i_index;
-
             MISSING( "inputdeln" );
  
-            i_index = atoi( psz_value );
-            if( i_index > 0 && i_index <= p_cfg->i_input )
-                TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] );
+            int idx = atoi( psz_value );
+            if( idx > 0 && idx <= p_cfg->i_input )
+                TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[idx-1] );
             i++;
         }
         else if( !strcmp( psz_option, "output" ) )



More information about the vlc-commits mailing list