From 0ff86bf8a28a080340f600cb8561815fc43e3b4a Mon Sep 17 00:00:00 2001
From: Ilkka Ollakka <ileoo@videolan.org>
Date: Wed, 5 Jul 2023 15:09:57 +0300
Subject: [PATCH] avcodec/audio: make channel mapping array 0 terminated

Also change pi_channels_src to be only AOUT_CHAN_MAX instead of same
size as mapping array.
---
 modules/codec/avcodec/audio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 2c85d83005c5..d0c8bae750b2 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -585,6 +585,7 @@ static const uint64_t pi_channels_map[][2] =
     { AV_CH_TOP_BACK_RIGHT,    0 },
     { AV_CH_STEREO_LEFT,       0 },
     { AV_CH_STEREO_RIGHT,      0 },
+    { 0, 0 },
 };
 
 static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
@@ -617,8 +618,7 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
     }
 #endif
 
-    const unsigned i_order_max = sizeof(pi_channels_map)/sizeof(*pi_channels_map);
-    uint32_t pi_order_src[i_order_max];
+    uint32_t pi_order_src[AOUT_CHAN_MAX] = { 0 };
 
     int i_channels_src = 0;
 #if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
@@ -633,7 +633,7 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
 
     if( channel_layout_mask )
     {
-        for( unsigned i = 0; i < i_order_max
+        for( unsigned i = 0; pi_channels_map[i][0]
          && i_channels_src < channel_count; i++ )
         {
             if( channel_layout_mask & pi_channels_map[i][0] )
-- 
GitLab