[vlc-devel] commit: Equalizer: fix invalid sprintf() usage - fixes #2424 ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed Jan 21 20:13:32 CET 2009


vlc | branch: 0.9-bugfix | Rémi Denis-Courmont <rdenis at simphalempin.com> | Wed Jan 21 21:11:58 2009 +0200| [6680e8d54f694ad86e7da2658ff3e5925616d5bb] | committer: Rémi Denis-Courmont 

Equalizer: fix invalid sprintf() usage - fixes #2424
(cherry picked from commit a6b0ee0b7045b8b9788c2c23d8bcd6ed5decef4f)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6680e8d54f694ad86e7da2658ff3e5925616d5bb
---

 modules/audio_filter/equalizer.c |   72 +++++++++++++++++++-------------------
 1 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/modules/audio_filter/equalizer.c b/modules/audio_filter/equalizer.c
index de34760..a0a3bf4 100644
--- a/modules/audio_filter/equalizer.c
+++ b/modules/audio_filter/equalizer.c
@@ -505,52 +505,52 @@ static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
     aout_instance_t *p_aout = (aout_instance_t *)p_this;
 
     char *psz_preset = newval.psz_string;
-    char psz_newbands[120];
 
-    memset( psz_newbands, 0, 120 );
+    if( !*psz_preset || p_sys->i_band != 10 )
+        return VLC_SUCCESS;
 
-    if( *psz_preset && p_sys->i_band == 10 )
+    for( unsigned i = 0; eqz_preset_10b[i] != NULL; i++ )
     {
-        int i;
-        /* */
-        for( i = 0; eqz_preset_10b[i] != NULL; i++ )
+        if( !strcasecmp( eqz_preset_10b[i]->psz_name, psz_preset ) )
         {
-            if( !strcasecmp( eqz_preset_10b[i]->psz_name, psz_preset ) )
+            char *psz_newbands = NULL;
+
+            p_sys->f_gamp *= pow( 10, eqz_preset_10b[i]->f_preamp / 20.0 );
+            for( int j = 0; j < p_sys->i_band; j++ )
             {
-                int j;
-                p_sys->f_gamp *= pow( 10, eqz_preset_10b[i]->f_preamp / 20.0 );
-                for( j = 0; j < p_sys->i_band; j++ )
-                {
-                    lldiv_t div;
-                    p_sys->f_amp[j] = EqzConvertdB(
-                                        eqz_preset_10b[i]->f_amp[j] );
-                    div = lldiv( eqz_preset_10b[i]->f_amp[j] * 10000000,
-                                 10000000 );
-                    sprintf( psz_newbands, "%s %"PRId64".%07u", psz_newbands,
-                                      (int64_t)div.quot, (unsigned int) div.rem );
-                }
-                if( p_sys->b_first == false )
+                lldiv_t d;
+                char *psz;
+
+                p_sys->f_amp[j] = EqzConvertdB( eqz_preset_10b[i]->f_amp[j] );
+                d = lldiv( eqz_preset_10b[i]->f_amp[j] * 10000000, 10000000 );
+                if( asprintf( &psz, "%s %lld.%07llu",
+                              psz_newbands ? psz_newbands : "",
+                              d.quot, d.rem ) == -1 )
                 {
-                    var_SetString( p_aout, "equalizer-bands", psz_newbands );
-                    var_SetFloat( p_aout, "equalizer-preamp",
-                                    eqz_preset_10b[i]->f_preamp );
+                    free( psz_newbands );
+                    return VLC_ENOMEM;
                 }
-                else
-                {
-                    p_sys->psz_newbands = strdup( psz_newbands );
-                    p_sys->f_newpreamp = eqz_preset_10b[i]->f_preamp;
-                }
-                break;
+                psz_newbands = psz;
             }
-        }
-        if( eqz_preset_10b[i] == NULL )
-        {
-            msg_Err( p_aout, "equalizer preset '%s' not found", psz_preset );
-            msg_Dbg( p_aout, "full list:" );
-            for( i = 0; eqz_preset_10b[i] != NULL; i++ )
-                msg_Dbg( p_aout, "  - '%s'", eqz_preset_10b[i]->psz_name );
+            if( p_sys->b_first == false )
+            {
+                var_SetString( p_aout, "equalizer-bands", psz_newbands );
+                var_SetFloat( p_aout, "equalizer-preamp",
+                              eqz_preset_10b[i]->f_preamp );
+                free( psz_newbands );
+            }
+            else
+            {
+                p_sys->psz_newbands = psz_newbands;
+                p_sys->f_newpreamp = eqz_preset_10b[i]->f_preamp;
+            }
+            return VLC_SUCCESS;
         }
     }
+    msg_Err( p_aout, "equalizer preset '%s' not found", psz_preset );
+    msg_Info( p_aout, "full list:" );
+    for( unsigned i = 0; eqz_preset_10b[i] != NULL; i++ )
+         msg_Info( p_aout, "  - '%s'", eqz_preset_10b[i]->psz_name );
     return VLC_SUCCESS;
 }
 




More information about the vlc-devel mailing list