diff mbox series

[FFmpeg-devel,2/4] avutil/detection_bbox: use offsetof for bboxes_offset

Message ID 1632836198-23044-2-git-send-email-lance.lmwang@gmail.com
State Accepted
Commit e724004fd8d2c5d7753f7b997e3d02a2155ceef6
Headers show
Series [FFmpeg-devel,1/4] avutil/detection_bbox: fix the memory leak on error | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Lance Wang Sept. 28, 2021, 1:36 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavutil/detection_bbox.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/detection_bbox.c b/libavutil/detection_bbox.c
index d066567..8bfdff7 100644
--- a/libavutil/detection_bbox.c
+++ b/libavutil/detection_bbox.c
@@ -21,10 +21,11 @@ 
 AVDetectionBBoxHeader *av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_size)
 {
     size_t size;
-    struct {
+    struct BBoxContext {
         AVDetectionBBoxHeader header;
         AVDetectionBBox boxes[1];
     } *ret;
+    const size_t bboxes_offset = offsetof(struct BBoxContext, boxes);
 
     size = sizeof(*ret);
     if (nb_bboxes - 1 > (SIZE_MAX - size) / sizeof(*ret->boxes))
@@ -37,7 +38,7 @@  AVDetectionBBoxHeader *av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_s
 
     ret->header.nb_bboxes = nb_bboxes;
     ret->header.bbox_size = sizeof(*ret->boxes);
-    ret->header.bboxes_offset = (char *)&ret->boxes - (char *)&ret->header;
+    ret->header.bboxes_offset = bboxes_offset;
 
     if (out_size)
         *out_size = size;