avcodec/audio: make channel mapping array 0 terminated
authorIlkka Ollakka <ileoo@videolan.org>
Wed, 5 Jul 2023 12:09:57 +0000 (15:09 +0300)
committerSebastian Ramacher <sramacher@debian.org>
Tue, 21 Jan 2025 18:02:47 +0000 (19:02 +0100)
Also change pi_channels_src to be only AOUT_CHAN_MAX instead of same
size as mapping array.

(cherry picked from commit 0ff86bf8a28a080340f600cb8561815fc43e3b4a) (rebased)
rebased:
- the code around is slightly different

Gbp-Pq: Name 0090-avcodec-audio-make-channel-mapping-array-0-terminate.patch

modules/codec/avcodec/audio.c

index 20744010433bcd890a920a6aab1271943578062c..04c540173bf9cba963ae1b92a81509ad137fa12e 100644 (file)
@@ -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, channel_count;
     uint64_t channel_layout_mask;
@@ -637,7 +637,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] )