Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] lavu/video_enc_params: Avoid relying on an undefined C construct
@ 2023-01-15 22:47 Martin Storsjö
  2023-01-18  9:38 ` Anton Khirnov
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Storsjö @ 2023-01-15 22:47 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Martin Storsjö, Anton Khirnov

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].

Current Clang git main got a patch [2] which changed this construct
into a hard error. It seems like this will be softened into a
warning [3] soon though, as it did break a fair number of projects.

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://github.com/llvm/llvm-project/commit/e327b52766ed497e4779f4e652b9ad237dfda8e6
[3] https://reviews.llvm.org/D133574#4053647

Signed-off-by: Martin Storsjö <martin@martin.st>
---
 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;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-31 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-15 22:47 [FFmpeg-devel] [PATCH] lavu/video_enc_params: Avoid relying on an undefined C construct Martin Storsjö
2023-01-18  9:38 ` Anton Khirnov
2023-01-31 12:37   ` Martin Storsjö

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git