From: Marton Balint <cus@passwd.hu> To: ffmpeg-devel@ffmpeg.org Cc: Marton Balint <cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 1/4] avformat/mov_chan: check channel count at compile time by using a nonconst expression Date: Mon, 1 Apr 2024 20:56:18 +0200 Message-ID: <20240401185621.15297-1-cus@passwd.hu> (raw) If the channel tag does not match the number of channels, the constant expression evaluation should fail. Signed-off-by: Marton Balint <cus@passwd.hu> --- libavformat/mov_chan.c | 48 +++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index e7d181d71f..6ccc26b3f1 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -81,24 +81,28 @@ struct MovChannelLayoutMap { }; }; -#define TAG(_0) {.tag = _0} -#define ID(_0) {.id = c_##_0} -#define CHLIST(_0, ...) TAG(_0), __VA_ARGS__ -#define CHLIST01(_0, _1) CHLIST(_0, ID(_1)) -#define CHLIST02(_0, _1, _2) CHLIST(_0, ID(_1), ID(_2)) -#define CHLIST03(_0, _1, _2, _3) CHLIST(_0, ID(_1), ID(_2), ID(_3)) -#define CHLIST04(_0, _1, _2, _3, _4) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4)) -#define CHLIST05(_0, _1, _2, _3, _4, _5) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5)) -#define CHLIST06(_0, _1, _2, _3, _4, _5, _6) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6)) -#define CHLIST07(_0, _1, _2, _3, _4, _5, _6, _7) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7)) -#define CHLIST08(_0, _1, _2, _3, _4, _5, _6, _7, _8) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8)) -#define CHLIST09(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9)) -#define CHLIST16(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) \ - CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ - ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16)) -#define CHLIST21(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21) \ - CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ - ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16), ID(_17), ID(_18), ID(_19), ID(_20), ID(_21)) +static int nonconst_expr(void) { + return 0; +} + +#define TAG(_tag, _cnt) {.tag = (_tag & 0xffff) == _cnt ? _tag : nonconst_expr()} +#define ID(_0) {.id = c_##_0} +#define CHLIST(_tag, _cnt, ...) TAG(_tag, _cnt), __VA_ARGS__ +#define CHLIST01(_tag, _1) CHLIST(_tag, 1, ID(_1)) +#define CHLIST02(_tag, _1, _2) CHLIST(_tag, 2, ID(_1), ID(_2)) +#define CHLIST03(_tag, _1, _2, _3) CHLIST(_tag, 3, ID(_1), ID(_2), ID(_3)) +#define CHLIST04(_tag, _1, _2, _3, _4) CHLIST(_tag, 4, ID(_1), ID(_2), ID(_3), ID(_4)) +#define CHLIST05(_tag, _1, _2, _3, _4, _5) CHLIST(_tag, 5, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5)) +#define CHLIST06(_tag, _1, _2, _3, _4, _5, _6) CHLIST(_tag, 6, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6)) +#define CHLIST07(_tag, _1, _2, _3, _4, _5, _6, _7) CHLIST(_tag, 7, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7)) +#define CHLIST08(_tag, _1, _2, _3, _4, _5, _6, _7, _8) CHLIST(_tag, 8, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8)) +#define CHLIST09(_tag, _1, _2, _3, _4, _5, _6, _7, _8, _9) CHLIST(_tag, 9, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9)) +#define CHLIST16(_tag, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) \ + CHLIST(_tag, 16, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ + ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16)) +#define CHLIST21(_tag, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21) \ + CHLIST(_tag, 21, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ + ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16), ID(_17), ID(_18), ID(_19), ID(_20), ID(_21)) static const struct MovChannelLayoutMap mov_ch_layout_map[] = { CHLIST01( MOV_CH_LAYOUT_MONO, C ), @@ -281,14 +285,6 @@ static const struct { static const struct MovChannelLayoutMap* find_layout_map(uint32_t tag) { -#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1 - { - int i; - for (i = 0; i < FF_ARRAY_ELEMS(mov_ch_layout_map); i += 1 + (mov_ch_layout_map[i].tag & 0xffff)) - av_assert2(mov_ch_layout_map[i].tag & 0xffff0000); - av_assert2(i == FF_ARRAY_ELEMS(mov_ch_layout_map)); - } -#endif for (int i = 0; i < FF_ARRAY_ELEMS(mov_ch_layout_map); i += 1 + (mov_ch_layout_map[i].tag & 0xffff)) if (mov_ch_layout_map[i].tag == tag) return &mov_ch_layout_map[i + 1]; -- 2.35.3 _______________________________________________ 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".
next reply other threads:[~2024-04-01 18:56 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-01 18:56 Marton Balint [this message] 2024-04-01 18:56 ` [FFmpeg-devel] [PATCH 2/4] avformat/mov_chan: factorize some layout map search functions Marton Balint 2024-04-01 18:56 ` [FFmpeg-devel] [PATCH 3/4] avformat/mov_chan: respect channel order when parsing and creating chnl atom Marton Balint 2024-04-01 19:37 ` James Almer 2024-04-01 20:43 ` Marton Balint 2024-04-01 18:56 ` [FFmpeg-devel] [PATCH 4/4] avformat/mov_chan: add support for omitted_channel bitmask in " Marton Balint 2024-04-01 20:41 ` [FFmpeg-devel] [PATCH 1/4] avformat/mov_chan: check channel count at compile time by using a nonconst expression Andreas Rheinhardt 2024-04-02 22:40 ` [FFmpeg-devel] [PATCH v2 1/4] avformat/mov_chan: check channel count of layout tags at compile time Marton Balint 2024-04-08 19:48 ` Marton Balint
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240401185621.15297-1-cus@passwd.hu \ --to=cus@passwd.hu \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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