diff mbox series

[FFmpeg-devel,06/10] avcodec/ratecontrol: Avoid function pointer casts

Message ID GV1P250MB0737D801F568B88280148CE08F362@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 6edd83c0e2f9fc4b483c497485423281b376a7f5
Headers show
Series [FFmpeg-devel,01/10] doc/examples: Always use <> includes | 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 March 25, 2024, 1:53 a.m. UTC
It is undefined behaviour to call a function with a different
signature for the call than the actual function signature;
there are no exceptions for void* and RateControlEntry*.

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

Patch

diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 1e861e20c1..1ff209c00b 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -79,6 +79,11 @@  static inline double qp2bits(RateControlEntry *rce, double qp)
     return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits + 1) / qp;
 }
 
+static double qp2bits_cb(void *rce, double qp)
+{
+    return qp2bits(rce, qp);
+}
+
 static inline double bits2qp(RateControlEntry *rce, double bits)
 {
     if (bits < 0.9) {
@@ -87,6 +92,11 @@  static inline double bits2qp(RateControlEntry *rce, double bits)
     return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits + 1) / bits;
 }
 
+static double bits2qp_cb(void *rce, double qp)
+{
+    return bits2qp(rce, qp);
+}
+
 static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, double q)
 {
     RateControlContext *rcc   = &s->rc_context;
@@ -507,8 +517,8 @@  av_cold int ff_rate_control_init(MpegEncContext *s)
         NULL
     };
     static double (* const func1[])(void *, double) = {
-        (double (*)(void *, double)) bits2qp,
-        (double (*)(void *, double)) qp2bits,
+        bits2qp_cb,
+        qp2bits_cb,
         NULL
     };
     static const char * const func1_names[] = {