X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Fmathematics.c;h=0485db7222fdd520fb40831a244326af94b729bf;hb=1e6cef686183288a50eb4e45265a3a7f7582b1b5;hp=1bf044cdf114f7d789b36ce0070e12d193e492a4;hpb=409e684e79b6ee0c511292326f09b13fe230e58e;p=ffmpeg diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c index 1bf044cdf11..0485db7222f 100644 --- a/libavutil/mathematics.c +++ b/libavutil/mathematics.c @@ -198,7 +198,7 @@ int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t i m = inc_tb.num * (int64_t)ts_tb.den; d = inc_tb.den * (int64_t)ts_tb.num; - if (m % d == 0) + if (m % d == 0 && ts <= INT64_MAX - m / d) return ts + m / d; if (m < d) return ts; @@ -206,6 +206,10 @@ int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t i { int64_t old = av_rescale_q(ts, ts_tb, inc_tb); int64_t old_ts = av_rescale_q(old, inc_tb, ts_tb); + + if (old == INT64_MAX) + return ts; + return av_rescale_q(old + 1, inc_tb, ts_tb) + (ts - old_ts); } }