[vlc-devel] [PATCH] audio_output/file: Fix a segmentation fault

Farid Hammane farid.hammane at gmail.com
Sat Jan 4 21:48:00 CET 2020


Fix segmentation fault that occurred when
unsupported "audiofile-format" was selected.
---
 modules/audio_output/file.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/modules/audio_output/file.c b/modules/audio_output/file.c
index 283b8415c9..303dc88436 100644
--- a/modules/audio_output/file.c
+++ b/modules/audio_output/file.c
@@ -131,8 +131,8 @@ vlc_module_end ()
 static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
 {
     char * psz_name, * psz_format;
-    const char * const * ppsz_compare = format_list;
     int i_channels, i = 0;
+    int format_list_size;
 
     if( aout_FormatNbChannels( fmt ) == 0 )
         return VLC_EGENERIC;
@@ -178,16 +178,16 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
         return VLC_EGENERIC;
     }
 
-    while ( *ppsz_compare != NULL )
+    format_list_size = (int)(sizeof(format_list) / sizeof(*format_list));
+    for (i = 0; i < format_list_size; i++)
     {
-        if ( !strncmp( *ppsz_compare, psz_format, strlen(*ppsz_compare) ) )
+        if ( !strncmp( format_list[i], psz_format, strlen(format_list[i]) ) )
         {
             break;
         }
-        ppsz_compare++; i++;
     }
 
-    if ( *ppsz_compare == NULL )
+    if ( i == format_list_size )
     {
         msg_Err( p_aout, "cannot understand the format string (%s)",
                  psz_format );
-- 
2.20.1



More information about the vlc-devel mailing list