diff mbox series

[FFmpeg-devel] lavu/video_enc_params: make sure blocks are properly aligned

Message ID 20210531185147.27314-1-anton@khirnov.net
State Accepted
Commit c8778606b3811da6bd58ca6b73d2446bd430013e
Headers show
Series [FFmpeg-devel] lavu/video_enc_params: make sure blocks are properly aligned | expand

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

Anton Khirnov May 31, 2021, 6:51 p.m. UTC
---
 libavutil/video_enc_params.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/video_enc_params.c b/libavutil/video_enc_params.c
index b9cdafddbb..7d903af385 100644
--- a/libavutil/video_enc_params.c
+++ b/libavutil/video_enc_params.c
@@ -29,10 +29,14 @@ 
 AVVideoEncParams *av_video_enc_params_alloc(enum AVVideoEncParamsType type,
                                             unsigned int nb_blocks, size_t *out_size)
 {
+    const size_t blocks_offset = offsetof(
+        struct {
+            AVVideoEncParams   p;
+            AVVideoBlockParams b;
+        }, b);
+    size_t size = blocks_offset;
     AVVideoEncParams *par;
-    size_t size;
 
-    size = sizeof(*par);
     if (nb_blocks > (SIZE_MAX - size) / sizeof(AVVideoBlockParams))
         return NULL;
     size += sizeof(AVVideoBlockParams) * nb_blocks;
@@ -44,7 +48,7 @@  AVVideoEncParams *av_video_enc_params_alloc(enum AVVideoEncParamsType type,
     par->type          = type;
     par->nb_blocks     = nb_blocks;
     par->block_size    = sizeof(AVVideoBlockParams);
-    par->blocks_offset = sizeof(*par);
+    par->blocks_offset = blocks_offset;
 
     if (out_size)
         *out_size = size;