diff mbox series

[FFmpeg-devel,12/17] Avoid calling functions repeatedly via FFMIN

Message ID HE1PR0301MB2154E31EF7006D49E2ED6ABC8F319@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit f9136d6026ede3a98f3bffc23e1deacca37cbf3b
Headers show
Series [FFmpeg-devel,01/17] avcodec/avcodec: Stop including bsf.h in avcodec.h
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt June 14, 2021, 10:41 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/pngdec.c  | 4 +++-
 libavformat/afc.c    | 4 ++--
 libavformat/avidec.c | 3 ++-
 3 files changed, 7 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 16c4c3a283..3c00007907 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1044,7 +1044,9 @@  static void handle_p_frame_png(PNGDecContext *s, AVFrame *p)
     int i, j;
     uint8_t *pd      = p->data[0];
     uint8_t *pd_last = s->last_picture.f->data[0];
-    int ls = FFMIN(av_image_get_linesize(p->format, s->width, 0), s->width * s->bpp);
+    int ls = av_image_get_linesize(p->format, s->width, 0);
+
+    ls = FFMIN(ls, s->width * s->bpp);
 
     ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
     for (j = 0; j < s->height; j++) {
diff --git a/libavformat/afc.c b/libavformat/afc.c
index a99f65472d..102b74baeb 100644
--- a/libavformat/afc.c
+++ b/libavformat/afc.c
@@ -57,10 +57,10 @@  static int afc_read_header(AVFormatContext *s)
 static int afc_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     AFCDemuxContext *c = s->priv_data;
-    int64_t size;
+    int64_t size = c->data_end - avio_tell(s->pb);
     int ret;
 
-    size = FFMIN(c->data_end - avio_tell(s->pb), 18 * 128);
+    size = FFMIN(size, 18 * 128);
     if (size <= 0)
         return AVERROR_EOF;
 
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 14a2dd6cd7..2e175b3179 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -363,7 +363,8 @@  static void avi_read_nikon(AVFormatContext *s, uint64_t end)
                 uint16_t size    = avio_rl16(s->pb);
                 const char *name = NULL;
                 char buffer[64]  = { 0 };
-                size = FFMIN(size, tag_end - avio_tell(s->pb));
+                uint64_t remaining = tag_end - avio_tell(s->pb);
+                size = FFMIN(size, remaining);
                 size -= avio_read(s->pb, buffer,
                                   FFMIN(size, sizeof(buffer) - 1));
                 switch (tag) {