From: "Tomas Härdin" <git@haerdin.se>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 5/5] lavu/mathematics: Return early if either a or b is zero
Date: Thu, 30 May 2024 00:15:27 +0200
Message-ID: <cfc903599594c0b12c3fc1f79fd236ebcc74ae73.camel@haerdin.se> (raw)
In-Reply-To: <27e5f614496e729f68326a31c3ac70d5923cfa97.camel@haerdin.se>
[-- Attachment #1: Type: text/plain, Size: 119 bytes --]
This doesn't really fix anything, it just makes the value analysis
easier. I don't feel strongly about it.
/Tomas
[-- Attachment #2: 0005-lavu-mathematics-Return-early-if-either-a-or-b-is-ze.patch --]
[-- Type: text/x-patch, Size: 1252 bytes --]
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
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-05-29 22:15 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 22:13 [FFmpeg-devel] [PATCH 1/5] lavu/common.h: Fix UB in av_clipl_int32_c() Tomas Härdin
2024-05-29 22:13 ` [FFmpeg-devel] [PATCH 2/5] lavu/common.h: Fix UB in av_clip_intp2_c() Tomas Härdin
2024-05-29 22:24 ` Andreas Rheinhardt
2024-05-29 23:08 ` Tomas Härdin
2024-05-29 22:14 ` [FFmpeg-devel] [PATCH 3/5] lavu/common.h: Fix UB in av_clip_uintp2_c() Tomas Härdin
2024-05-31 0:27 ` Michael Niedermayer
2024-05-29 22:14 ` [FFmpeg-devel] [PATCH 4/5] lavu/intmath.h: Fix UB in ff_ctz_c() and ff_ctzll_c() Tomas Härdin
2024-05-30 7:54 ` Rémi Denis-Courmont
2024-05-30 9:50 ` Tomas Härdin
2024-05-30 12:29 ` Hendrik Leppkes
2024-05-30 13:06 ` Rémi Denis-Courmont
2024-05-30 14:03 ` Tomas Härdin
2024-05-30 14:32 ` Rémi Denis-Courmont
2024-05-31 0:43 ` Ronald S. Bultje
2024-05-31 0:41 ` Michael Niedermayer
2024-05-31 5:48 ` Rémi Denis-Courmont
2024-05-31 0:31 ` Michael Niedermayer
2024-05-29 22:15 ` Tomas Härdin [this message]
2024-05-31 0:22 ` [FFmpeg-devel] [PATCH 5/5] lavu/mathematics: Return early if either a or b is zero Michael Niedermayer
2024-05-31 15:21 ` Tomas Härdin
2024-05-29 22:31 ` [FFmpeg-devel] [PATCH 1/5] lavu/common.h: Fix UB in av_clipl_int32_c() Andreas Rheinhardt
2024-05-30 9:48 ` Tomas Härdin
2024-05-30 6:41 ` Rémi Denis-Courmont
2024-05-30 9:40 ` Tomas Härdin
2024-05-30 11:50 ` Rémi Denis-Courmont
2024-05-30 14:07 ` Tomas Härdin
2024-05-30 14:28 ` Rémi Denis-Courmont
2024-05-30 15:32 ` Tomas Härdin
2024-05-30 15:38 ` Rémi Denis-Courmont
2024-05-31 1:03 ` Michael Niedermayer
2024-06-03 7:32 ` Rémi Denis-Courmont
2024-06-03 21:21 ` Michael Niedermayer
2024-05-30 15:42 ` James Almer
2024-05-30 16:48 ` Tomas Härdin
2024-05-30 17:49 ` Rémi Denis-Courmont
2024-05-30 19:07 ` Michael Niedermayer
2024-05-30 19:20 ` Rémi Denis-Courmont
2024-05-31 15:23 ` Tomas Härdin
2024-06-14 12:31 ` Tomas Härdin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cfc903599594c0b12c3fc1f79fd236ebcc74ae73.camel@haerdin.se \
--to=git@haerdin.se \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git