diff mbox series

[FFmpeg-devel,5/5] lavu/mathematics: Return early if either a or b is zero

Message ID cfc903599594c0b12c3fc1f79fd236ebcc74ae73.camel@haerdin.se
State New
Headers show
Series [FFmpeg-devel,1/5] lavu/common.h: Fix UB in av_clipl_int32_c() | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Tomas Härdin May 29, 2024, 10:15 p.m. UTC
This doesn't really fix anything, it just makes the value analysis
easier. I don't feel strongly about it.

/Tomas

Comments

Michael Niedermayer May 31, 2024, 12:22 a.m. UTC | #1
On Thu, May 30, 2024 at 12:15:27AM +0200, Tomas Härdin wrote:
> This doesn't really fix anything, it just makes the value analysis
> easier. I don't feel strongly about it.

if it doesnt fix anything and it doesnt make the code faster
for our usecases, then i would say that it shouldnt be in a
production build

but not feeling strongly about this either

thx

[...]
Tomas Härdin May 31, 2024, 3:21 p.m. UTC | #2
fre 2024-05-31 klockan 02:22 +0200 skrev Michael Niedermayer:
> On Thu, May 30, 2024 at 12:15:27AM +0200, Tomas Härdin wrote:
> > This doesn't really fix anything, it just makes the value analysis
> > easier. I don't feel strongly about it.
> 
> if it doesnt fix anything and it doesnt make the code faster
> for our usecases, then i would say that it shouldnt be in a
> production build
> 
> but not feeling strongly about this either

I'll hold off on this one for the time being since again it's mostly
there to make analysis easier. I have an even more *interesting* change
that defaults to the long division version in more cases which makes
things slower for the sake of correctness

I'll push the other four patches in a day or two since the only real
feedback was cosmetic, and we can discuss cosmetics until the cows come
home

/Tomas
diff mbox series

Patch

From cf9c56d7d4d7325d51ba6d99259431be7fca1f67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@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