[FFmpeg-devel] [PATCH] lavu/video_enc_params: Avoid relying on an undefined C construct
Anton Khirnov
anton at khirnov.net
Wed Jan 18 11:38:26 EET 2023
Quoting Martin Storsjö (2023-01-15 23:47:41)
> 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 at 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
LGTM
--
Anton Khirnov
More information about the ffmpeg-devel
mailing list