[FFmpeg-devel] [PATCH]lavu/threadmessage: Properly declare a function pointer

Nicolas George george at nsup.org
Sat May 2 12:06:31 EEST 2020


Carl Eugen Hoyos (12020-05-01):
> Hi!
> 
> Attached patch, inspired by a patch by Andreas, fixes the following
> warning when -Wpedantic is used:
> CC      libavutil/threadmessage.o
> libavutil/threadmessage.c: In function ‘av_thread_message_flush’:
> libavutil/threadmessage.c:222:23: warning: ISO C forbids
> initialization between function pointer and ‘void *’ [-Wpedantic]
>   222 |     void *free_func = mq->free_func;
>       |                       ^~
> 
> 
> Please comment, Carl Eugen

> From 3f0b6c654b7473452638c1cc06dfe45eebb59079 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <ceffmpeg at gmail.com>
> Date: Fri, 1 May 2020 23:42:01 +0200
> Subject: [PATCH] lavu/threadmessage: Properly declare a function pointer.
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> Fixes a pedantic warning:
> libavutil/threadmessage.c:222:23: warning: ISO C forbids initialization between function pointer and ‘void *’
> ---
>  libavutil/threadmessage.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
> index 764b7fb813..797ba6c44c 100644
> --- a/libavutil/threadmessage.c
> +++ b/libavutil/threadmessage.c
> @@ -219,7 +219,7 @@ void av_thread_message_flush(AVThreadMessageQueue *mq)
>  {
>  #if HAVE_THREADS
>      int used, off;
> -    void *free_func = mq->free_func;
> +    void(*free_func)(void *) = mq->free_func;
>  
>      pthread_mutex_lock(&mq->lock);
>      used = av_fifo_size(mq->fifo);

This is not ok. Now free_func is properly a function pointer, but it is
later still used as a void *, it is as much invalid as it was before.

I thin it could work:

    void *free_funcp = &mq->free_func; // pointer to data

and in free_func_wrap():

void (*free_func)(void *) = *((void (*)(void *)) *)arg;

But that needs testing.

Do we support an arch where function pointers are different?

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200502/45ec7381/attachment.sig>


More information about the ffmpeg-devel mailing list