[FFmpeg-cvslog] avutil/common: Fix underflow for ROUNDED_DIV with unsigned integer

Mengye Lv git at videolan.org
Sun Oct 6 12:34:17 EEST 2019


ffmpeg | branch: master | Mengye Lv <mengyelv at tencent.com> | Wed Oct  2 10:30:45 2019 +0800| [9f353e376b161eb16a78fd7ad727c9513ac60d13] | committer: Jun Zhao

avutil/common: Fix underflow for ROUNDED_DIV with unsigned integer

When used ROUNDED_DIV(a,b), if a is unsigned integer zero, it's
will lead to an underflow issue(it called unsigned integer
wrapping).

Fixes #8062

Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Mengye Lv <mengyelv at tencent.com>
Signed-off-by: Jun Zhao <barryjzhao at tencent.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9f353e376b161eb16a78fd7ad727c9513ac60d13
---

 libavutil/common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/common.h b/libavutil/common.h
index af35397eb9..f09f0b486b 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -53,7 +53,7 @@
 //rounded division & shift
 #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
 /* assume b>0 */
-#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
+#define ROUNDED_DIV(a,b) (((a)>=0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
 /* Fast a/(1<<b) rounded toward +inf. Assume a>=0 and b>=0 */
 #define AV_CEIL_RSHIFT(a,b) (!av_builtin_constant_p(b) ? -((-(a)) >> (b)) \
                                                        : ((a) + (1<<(b)) - 1) >> (b))



More information about the ffmpeg-cvslog mailing list