]> git.sesse.net Git - ffmpeg/commitdiff
avutil/video_enc_params: Combine overflow checks
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 14 Feb 2021 18:43:56 +0000 (19:43 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Fri, 19 Feb 2021 06:45:39 +0000 (07:45 +0100)
This patch also fixes a -Wtautological-constant-out-of-range-compare
warning from Clang and a -Wtype-limits warning from GCC on systems
where size_t is 64bits and unsigned 32bits. The reason for this seems
to be that variable (whose value derives from sizeof() and can therefore
be known at compile-time) is used instead of using sizeof() directly in
the comparison.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavutil/video_enc_params.c

index c46c0f1dc69f9e71cacb6e2b0b76069e9deb8974..b9cdafddbb43e2c75e465888efe974a3edf3866e 100644 (file)
@@ -33,8 +33,7 @@ AVVideoEncParams *av_video_enc_params_alloc(enum AVVideoEncParamsType type,
     size_t size;
 
     size = sizeof(*par);
-    if (nb_blocks > SIZE_MAX / sizeof(AVVideoBlockParams) ||
-        nb_blocks * sizeof(AVVideoBlockParams) > SIZE_MAX - size)
+    if (nb_blocks > (SIZE_MAX - size) / sizeof(AVVideoBlockParams))
         return NULL;
     size += sizeof(AVVideoBlockParams) * nb_blocks;