From patchwork Mon Apr 1 18:56:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 47698 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp922552pzb; Mon, 1 Apr 2024 11:56:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU3lAHHZdeZof0jzRbckSohDkGzMMXDvH3Eef28Q9mzk+BdthsLzSidV2zTRhdDOosjGCFrpDaWllZZTdZMd4WTQtgQhWO5TxtyVw== X-Google-Smtp-Source: AGHT+IErToytDh9lWshXgWt7nX+tWihptvhYhpmHrbzgPRopwxgcOLWLz3XRkSl/+uu8byuZzE77 X-Received: by 2002:a05:6402:27cb:b0:56d:206d:a6e with SMTP id c11-20020a05640227cb00b0056d206d0a6emr6599880ede.0.1711997798627; Mon, 01 Apr 2024 11:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711997798; cv=none; d=google.com; s=arc-20160816; b=KQvi1ciIArvn9G/jS3Z+/zAKmCK1v9hSwvi7kQ0rlIau+p387nIy6IIXjh/rwNv0Fr FvrcYyOEeDXXlXP2aG/A7T9hyExrnUjPmQWtUHK+8SNFfFjCq2gYrep1fnngWrtYO/HZ sGzeQV3QLrJkvyMsMMjvHaa7gGbJ9wy8TiBEounPk8BBM1vtMzBVssvaYVtEs+Cmt6Uy elJFBqaWlKh+w0AVfmj8mnNPfrSu4rSc8HP7k2RQSPz3ZEMrkIyjG0N2nqDW1RK+t455 3pyvLXrObCLohp2zggpeKqcwvYf2guE9WGwxKF9Ykm/ytshA0Kc3i92rYg72P+aWcne9 g9Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=YgnycRGKiYH+ByQQL77Y2dvBFnQlzQJcjv8qb8b/SKk=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=BhDi1FJXiZmerMDNXzNLS4CYeFTumTNcrNS7bdXFu08c9Ccc0dZ5iZwXxvuvW5IqjJ TFR0zXdNAIVl/RUc3CmLuLvaP2JzGhfCv2VZYjy1PblpwVSCOej7i56PeEpr2coAKO2K 93oqe2zVa0mQfBjMLq+1CdH0HwDoecP1Pj5z6bUxBHjm3TJv/Wohh+rDeMCElWvYoO1T OLsxFQ+yhJxLXSPw9XZ+5LNDynUM6UooGwFoPjfc5ZijH0Tneyb3vep3vARDeaZWJnoE UJj+0wOC6eBZJF2LH5e1oD+ANOhOb7icIvRxyeeD2bvdgvlYudb+C8zzK3AZZlKM2Wq/ 5K+Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b10-20020a056402350a00b0056c06f5b037si5100463edd.315.2024.04.01.11.56.38; Mon, 01 Apr 2024 11:56:38 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0B78F68CFD1; Mon, 1 Apr 2024 21:56:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DCCC868CC1C for ; Mon, 1 Apr 2024 21:56:29 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C3DCBEA2A1; Mon, 1 Apr 2024 20:56:29 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id k4s3wwOdKfqc; Mon, 1 Apr 2024 20:56:27 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9C3F7EA292; Mon, 1 Apr 2024 20:56:27 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 Apr 2024 20:56:18 +0200 Message-Id: <20240401185621.15297-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avformat/mov_chan: check channel count at compile time by using a nonconst expression X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +Uh5zKpZbws8 If the channel tag does not match the number of channels, the constant expression evaluation should fail. Signed-off-by: Marton Balint --- 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];