diff mbox series

[FFmpeg-devel,2/3] avutil/opt: Use correct function pointer type

Message ID AS8P250MB07448E8BC3024C7D581C07818F572@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit f705b8b5b4fb9390e2d1aeb9e864c099c8592d9d
Headers show
Series [FFmpeg-devel,1/3] avcodec/cbs_h266_syntax_template: Don't omit unused function parameter | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 21, 2024, 11:32 p.m. UTC
av_get_sample/pix_fmt() return their respective enums
and are therefore not of the type int (*)(const char*),
yet they are called as-if they were of this type.
This works in practice, but is actually undefined behaviour.

With Clang 17 UBSan these violations are flagged, affecting lots
of tests. The number of failing tests went down from 3363 to 164
here with this patch.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/opt.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Mark Thompson Feb. 24, 2024, 12:09 p.m. UTC | #1
On 21/02/2024 23:32, Andreas Rheinhardt wrote:
> av_get_sample/pix_fmt() return their respective enums
> and are therefore not of the type int (*)(const char*),
> yet they are called as-if they were of this type.
> This works in practice, but is actually undefined behaviour.
> 
> With Clang 17 UBSan these violations are flagged, affecting lots
> of tests. The number of failing tests went down from 3363 to 164
> here with this patch.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>   libavutil/opt.c | 14 ++++++++++++--
>   1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index d13b1ab504..0681b19896 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -444,16 +444,26 @@ static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t
>       return 0;
>   }
>   
> +static int get_pix_fmt(const char *name)
> +{
> +    return av_get_pix_fmt(name);
> +}
> +
>   static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
>   {
>       return set_string_fmt(obj, o, val, dst,
> -                          AV_PIX_FMT_NB, av_get_pix_fmt, "pixel format");
> +                          AV_PIX_FMT_NB, get_pix_fmt, "pixel format");
> +}
> +
> +static int get_sample_fmt(const char *name)
> +{
> +    return av_get_sample_fmt(name);
>   }
>   
>   static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
>   {
>       return set_string_fmt(obj, o, val, dst,
> -                          AV_SAMPLE_FMT_NB, av_get_sample_fmt, "sample format");
> +                          AV_SAMPLE_FMT_NB, get_sample_fmt, "sample format");
>   }
>   
>   static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)

1 and 2 of this set LGTM.

Thanks,

- Mark
diff mbox series

Patch

diff --git a/libavutil/opt.c b/libavutil/opt.c
index d13b1ab504..0681b19896 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -444,16 +444,26 @@  static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t
     return 0;
 }
 
+static int get_pix_fmt(const char *name)
+{
+    return av_get_pix_fmt(name);
+}
+
 static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
 {
     return set_string_fmt(obj, o, val, dst,
-                          AV_PIX_FMT_NB, av_get_pix_fmt, "pixel format");
+                          AV_PIX_FMT_NB, get_pix_fmt, "pixel format");
+}
+
+static int get_sample_fmt(const char *name)
+{
+    return av_get_sample_fmt(name);
 }
 
 static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
 {
     return set_string_fmt(obj, o, val, dst,
-                          AV_SAMPLE_FMT_NB, av_get_sample_fmt, "sample format");
+                          AV_SAMPLE_FMT_NB, get_sample_fmt, "sample format");
 }
 
 static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)