This doesn't really fix anything, it just makes the value analysis
easier. I don't feel strongly about it.

/Tomas
From cf9c56d7d4d7325d51ba6d99259431be7fca1f67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <g...@haerdin.se>
Date: Mon, 20 May 2024 14:46:01 +0200
Subject: [PATCH 5/5] lavu/mathematics: Return early if either a or b is zero

This removes the need to check b further down
---
 libavutil/mathematics.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index 61aeb7c029..06f6e61e78 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -71,6 +71,9 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
         rnd -= AV_ROUND_PASS_MINMAX;
     }
 
+    if (a == 0 || b == 0)
+        return 0;
+
     if (a < 0)
         return -(uint64_t)av_rescale_rnd(-FFMAX(a, -INT64_MAX), b, c, rnd ^ ((rnd >> 1) & 1));
 
@@ -85,7 +88,7 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
         else {
             int64_t ad = a / c;
             int64_t a2 = (a % c * b + r) / c;
-            if (ad >= INT32_MAX && b && ad > (INT64_MAX - a2) / b)
+            if (ad >= INT32_MAX && ad > (INT64_MAX - a2) / b)
                 return INT64_MIN;
             return ad * b + a2;
         }
-- 
2.39.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to