]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/mathematics.c
avcodec/h264_sei: print a log message when a unsupported ITU-T T35 SEI messages is...
[ffmpeg] / libavutil / mathematics.c
index 1bf044cdf114f7d789b36ce0070e12d193e492a4..da0fc17b2e655a33d35cb5711d55560f8406f8d2 100644 (file)
@@ -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);
-        return av_rescale_q(old + 1, inc_tb, ts_tb) + (ts - old_ts);
+
+        if (old == INT64_MAX || old == AV_NOPTS_VALUE || old_ts == AV_NOPTS_VALUE)
+            return ts;
+
+        return av_sat_add64(av_rescale_q(old + 1, inc_tb, ts_tb), ts - old_ts);
     }
 }