[vlc-commits] vlc_arrays: avoid variable shadowing warnings

Romain Vimont git at videolan.org
Wed Aug 29 12:02:36 CEST 2018


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Tue Aug 28 15:13:53 2018 +0200| [ce4e7b1af79ede26c9bf9f3bc48019a6ff775494] | committer: Jean-Baptiste Kempf

vlc_arrays: avoid variable shadowing warnings

Make the variable name depend on "item" to avoid variable shadowing
warnings for nested loops (even if this specific shadowing is harmless).

See previous discussion:
<https://mailman.videolan.org/pipermail/vlc-devel/2018-June/119489.html>

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 include/vlc_arrays.h | 9 ++++++---
 src/misc/events.c    | 8 +++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/include/vlc_arrays.h b/include/vlc_arrays.h
index e9cbc5daa6..0d6c2dd371 100644
--- a/include/vlc_arrays.h
+++ b/include/vlc_arrays.h
@@ -243,10 +243,13 @@ static inline void *realloc_or_free( void *p, size_t sz )
 #define ARRAY_BSEARCH(array, elem, zetype, key, answer) \
     BSEARCH( (array).p_elems, (array).i_size, elem, zetype, key, answer)
 
+/* append ##item to index variable name to avoid variable shadowing warnings for
+ * nested loops */
 #define ARRAY_FOREACH(item, array) \
-    for (int fe_idx = 0; \
-         fe_idx < (array).i_size && ((item) = (array).p_elems[fe_idx], 1); \
-         ++fe_idx)
+    for (int array_index_##item = 0; \
+         array_index_##item < (array).i_size && \
+            ((item) = (array).p_elems[array_index_##item], 1); \
+         ++array_index_##item)
 
 
 /************************************************************************
diff --git a/src/misc/events.c b/src/misc/events.c
index bf0ed8828b..a2273d654f 100644
--- a/src/misc/events.c
+++ b/src/misc/events.c
@@ -149,19 +149,17 @@ void vlc_event_detach( vlc_event_manager_t *p_em,
                        void *p_user_data )
 {
     vlc_event_listeners_group_t *slot = &p_em->events[event_type];
-    struct vlc_event_listener_t * listener;
 
     vlc_mutex_lock( &p_em->lock );
 
-    ARRAY_FOREACH( listener, slot->listeners )
+    for (int i = 0; i < slot->listeners.i_size; ++i)
     {
+        struct vlc_event_listener_t *listener = slot->listeners.p_elems[i];
         if( listener->pf_callback == pf_callback &&
             listener->p_user_data == p_user_data )
         {
             /* that's our listener */
-            ARRAY_REMOVE( slot->listeners,
-                          fe_idx /* This comes from the macro (and that's why
-                                    I hate macro) */ );
+            ARRAY_REMOVE( slot->listeners, i );
             vlc_mutex_unlock( &p_em->lock );
             free( listener );
             return;



More information about the vlc-commits mailing list