[vlc-devel] [PATCH] core: moved variable declaration to prevent compiler warning (gcc -Wclobbered)

Filip Roséen filip at videolabs.io
Wed May 11 16:47:33 CEST 2016


vlc_fifo_CleanupPush will effectivelly be replaced by
pthread_cleanup_push when vlc is compiled using pthreads (POSIX).

Having "paused" be declared after to the line in question will supress
the warning from gcc (regarding a potential clobbered (ie. changed)
value due to the implementation of pthread_cleanup_push).

--

Quoting $( man pthread_cleanup_push ):

> On Linux, the pthread_cleanup_push() and pthread_cleanup_pop()
> functions are implemented as macros that expand to text containing '{'
> and '}', respectively.  This means that variables declared within the
> scope of paired  calls to these functions will be visible within only
> that scope.

We do not care if "pause" is clobbered or not, but we do care about
warnings from the compiler.

In order to supress the compiler diagnostic all we need to do is move
"paused" to exists within the "invisible" scope introduced by
pthread_cleanup_push (making gcc see that it will not be used
during clean-up).

I tried creating a sample testcase for this issue, but it seems to be
reliant on too many factors to boil down in an easy manner.
---
 src/input/decoder.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 6a1ab6e..a0b01ed 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1448,12 +1448,13 @@ static void *DecoderThread( void *p_data )
 {
     decoder_t *p_dec = (decoder_t *)p_data;
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
-    bool paused = false;
 
     /* The decoder's main loop */
     vlc_fifo_Lock( p_owner->p_fifo );
     vlc_fifo_CleanupPush( p_owner->p_fifo );
 
+    bool paused = false;
+
     for( ;; )
     {
         if( p_owner->flushing )
-- 
2.8.2



More information about the vlc-devel mailing list