[FFmpeg-cvslog] lavu/video_enc_params: Avoid relying on an undefined C construct

Martin Storsjö git at videolan.org
Tue Jan 31 14:37:26 EET 2023


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Mon Jan 16 00:20:24 2023 +0200| [01f58f36465a13db069641cca47fa9777f03b875] | committer: Martin Storsjö

lavu/video_enc_params: Avoid relying on an undefined C construct

The construct of using offsetof on a (potentially anonymous) struct
defined within the offsetof expression, while supported by all
current compilers, has been declared explicitly undefined by the
C standards committee [1].

Clang recently got a change to identify this as an issue [2];
initially it was treated as a hard error, but it was soon after
softened into a warning under the -Wgnu-offsetof-extensions option
(not enabled automatically as part of -Wall though).

Nevertheless - in this particular case, it's trivial to fix the
code not to rely on the construct that the standards committee has
explicitly called out as undefined.

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm
[2] https://reviews.llvm.org/D133574

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=01f58f36465a13db069641cca47fa9777f03b875
---

 libavutil/video_enc_params.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavutil/video_enc_params.c b/libavutil/video_enc_params.c
index 54bfed0ed9..33592dc128 100644
--- a/libavutil/video_enc_params.c
+++ b/libavutil/video_enc_params.c
@@ -27,11 +27,11 @@
 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);
+    struct TestStruct {
+        AVVideoEncParams   p;
+        AVVideoBlockParams b;
+    };
+    const size_t blocks_offset = offsetof(struct TestStruct, b);
     size_t size = blocks_offset;
     AVVideoEncParams *par;
 



More information about the ffmpeg-cvslog mailing list