[vlc-devel] [PATCH 05/12] Replace variable-length arrays by calls to alloca() for C90 compliance.

Felix Abecassis felix.abecassis at gmail.com
Fri Nov 29 17:41:30 CET 2013


---
 src/audio_output/common.c |    2 +-
 src/config/chain.c        |    4 ++--
 src/config/file.c         |    2 +-
 src/input/item.c          |    2 +-
 src/input/stream.c        |    2 +-
 src/input/subtitles.c     |    8 ++++----
 src/misc/http_auth.c      |    4 ++--
 src/misc/messages.c       |    4 ++--
 src/misc/picture_pool.c   |    2 +-
 src/network/httpd.c       |    2 +-
 src/network/tcp.c         |    2 +-
 src/playlist/art.c        |    2 +-
 src/playlist/loadsave.c   |    2 +-
 src/stream_output/sdp.c   |    2 +-
 src/test/xmlent.c         |    2 +-
 15 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/audio_output/common.c b/src/audio_output/common.c
index d6d3776..df62d67 100644
--- a/src/audio_output/common.c
+++ b/src/audio_output/common.c
@@ -330,7 +330,7 @@ do { \
             assert( bytes != 0 );
             for( size_t i = 0; i < frames; i++ )
             {
-                unsigned char tmp[AOUT_CHAN_MAX * size];
+                unsigned char* tmp = alloca( sizeof(*tmp) * ( AOUT_CHAN_MAX * size ) );
 
                 for( size_t j = 0; j < channels; j++ )
                     memcpy( tmp + size * chans_table[j], buf + size * j, size );
diff --git a/src/config/chain.c b/src/config/chain.c
index 7d0b71d..03bbe44 100644
--- a/src/config/chain.c
+++ b/src/config/chain.c
@@ -279,7 +279,7 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
         if (optname[0] == '*')
             optname++;
 
-        char name[plen + strlen( optname )];
+        char* name = alloca( sizeof(*name) * ( plen + strlen( optname ) ) );
         snprintf( name, sizeof (name), "%s%s", psz_prefix, optname );
         if( var_Create( p_this, name,
                         config_GetType( p_this, name ) | VLC_VAR_DOINHERIT ) )
@@ -330,7 +330,7 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
         }
 
         /* create name */
-        char name[plen + strlen( ppsz_options[i] )];
+        char* name = alloca( sizeof(*name) * ( plen + strlen( ppsz_options[i] ) ) );
         const char *psz_name = name;
         snprintf( name, sizeof (name), "%s%s", psz_prefix,
                   b_once ? (ppsz_options[i] + 1) : ppsz_options[i] );
diff --git a/src/config/file.c b/src/config/file.c
index 1c0b876..5eab287 100644
--- a/src/config/file.c
+++ b/src/config/file.c
@@ -284,7 +284,7 @@ int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
         case ENOENT:
         {
             /* Let's try to create the parent directory */
-            char psz_parent[strlen( psz_dirname ) + 1], *psz_end;
+            char* psz_parent = alloca( sizeof(*psz_parent) * ( strlen( psz_dirname ) + 1 ) ), *psz_end;
             strcpy( psz_parent, psz_dirname );
 
             psz_end = strrchr( psz_parent, DIR_SEP_CHAR );
diff --git a/src/input/item.c b/src/input/item.c
index e225657..3f35ae9 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -772,7 +772,7 @@ void input_item_SetEpgOffline( input_item_t *p_item )
 #ifdef EPG_DEBUG
     vlc_mutex_lock( &p_item->lock );
     const int i_epg_info = p_item->i_epg;
-    char *ppsz_epg_info[i_epg_info];
+    char **ppsz_epg_info = alloca( sizeof(*ppsz_epg_info) * i_epg_info );
     for( int i = 0; i < p_item->i_epg; i++ )
     {
         const vlc_epg_t *p_epg = p_item->pp_epg[i];
diff --git a/src/input/stream.c b/src/input/stream.c
index 5788979..d5cbf06 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -252,7 +252,7 @@ stream_t *stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
     if( !psz_url )
         return NULL;
 
-    char psz_dup[strlen( psz_url ) + 1];
+    char* psz_dup = alloca( sizeof(*psz_dup) * ( strlen( psz_url ) + 1 ) );
     strcpy( psz_dup, psz_url );
     input_SplitMRL( &psz_access, &psz_demux, &psz_path, &psz_anchor, psz_dup );
 
diff --git a/src/input/subtitles.c b/src/input/subtitles.c
index 5a1a981..8ab2270 100644
--- a/src/input/subtitles.c
+++ b/src/input/subtitles.c
@@ -323,9 +323,9 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                 continue;
             }
 
-            char tmp_fname_noext[strlen( psz_name ) + 1];
-            char tmp_fname_trim[strlen( psz_name ) + 1];
-            char tmp_fname_ext[strlen( psz_name ) + 1];
+            char* tmp_fname_noext = alloca( sizeof(*tmp_fname_noext) * ( strlen(psz_name) + 1 ) );
+            char* tmp_fname_trim = alloca( sizeof(*tmp_fname_trim) * ( strlen(psz_name) + 1 ) );
+            char* tmp_fname_ext = alloca( sizeof(*tmp_fname_ext) * ( strlen(psz_name) + 1 ) );
             const char *tmp;
             int i_prio = SUB_PRIORITY_NONE;
 
@@ -362,7 +362,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             }
             if( i_prio >= i_fuzzy )
             {
-                char psz_path[strlen( psz_dir ) + strlen( psz_name ) + 2];
+                char* psz_path = alloca( sizeof(*psz_path) * ( strlen( psz_dir ) + strlen( psz_name ) + 2 ) );
                 struct stat st;
 
                 sprintf( psz_path, "%s"DIR_SEP"%s", psz_dir, psz_name );
diff --git a/src/misc/http_auth.c b/src/misc/http_auth.c
index 6b2bdf2..a070e54 100644
--- a/src/misc/http_auth.c
+++ b/src/misc/http_auth.c
@@ -45,7 +45,7 @@
  *****************************************************************************/
 static char *AuthGetParam( const char *psz_header, const char *psz_param )
 {
-    char psz_what[strlen(psz_param)+3];
+    char* psz_what = alloca( sizeof(*psz_what) * ( strlen(psz_param) + 3 ) );
     sprintf( psz_what, "%s=\"", psz_param );
     psz_header = strstr( psz_header, psz_what );
     if ( psz_header )
@@ -65,7 +65,7 @@ static char *AuthGetParam( const char *psz_header, const char *psz_param )
 
 static char *AuthGetParamNoQuotes( const char *psz_header, const char *psz_param )
 {
-    char psz_what[strlen(psz_param)+2];
+    char* psz_what = alloca( sizeof(*psz_what) * ( strlen(psz_param) + 2 ) );
     sprintf( psz_what, "%s=", psz_param );
     psz_header = strstr( psz_header, psz_what );
     if ( psz_header )
diff --git a/src/misc/messages.c b/src/misc/messages.c
index bffe24f..1c2a489 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -91,7 +91,7 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
     p = strchr(module, '.');
 
     size_t modlen = (p != NULL) ? (p - module) : 1;
-    char modulebuf[modlen + 1];
+    char* modulebuf = alloca( sizeof(*modulebuf) * ( modlen + 1 ) );
     if (p != NULL)
     {
         memcpy(modulebuf, module, modlen);
@@ -105,7 +105,7 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
 
 #ifndef __GLIBC__
     /* Expand %m to strerror(errno) - only once */
-    char buf[strlen(format) + 2001], *ptr;
+    char* buf = alloca( sizeof(*buf) * ( strlen(format) + 2001 ) ), *ptr;
     strcpy (buf, format);
     ptr = (char*)buf;
     format = (const char*) buf;
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 294d671..7c50c09 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -148,7 +148,7 @@ picture_pool_t *picture_pool_New(int picture_count, picture_t *picture[])
 
 picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt, int picture_count)
 {
-    picture_t *picture[picture_count];
+    picture_t **picture = alloca( sizeof(*picture) * picture_count );
 
     for (int i = 0; i < picture_count; i++) {
         picture[i] = picture_NewFromFormat(fmt);
diff --git a/src/network/httpd.c b/src/network/httpd.c
index ff7e653..8f25266 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -1950,7 +1950,7 @@ static void* httpd_HostThread( void *data )
     vlc_mutex_lock( &host->lock );
     while( host->i_ref > 0 )
     {
-        struct pollfd ufd[host->nfd + host->i_client];
+        struct pollfd* ufd = alloca( sizeof(*ufd) * ( host->nfd + host->i_client ) );
         unsigned nfd;
         for( nfd = 0; nfd < host->nfd; nfd++ )
         {
diff --git a/src/network/tcp.c b/src/network/tcp.c
index 78ab113..3593421 100644
--- a/src/network/tcp.c
+++ b/src/network/tcp.c
@@ -281,7 +281,7 @@ int net_Accept (vlc_object_t *p_this, int *pi_fd)
     unsigned n = 0;
     while (pi_fd[n] != -1)
         n++;
-    struct pollfd ufd[n + 1];
+    struct pollfd* ufd = alloca( sizeof(*ufd) * ( n + 1 ) );
 
     /* Initialize file descriptor set */
     for (unsigned i = 0; i <= n; i++)
diff --git a/src/playlist/art.c b/src/playlist/art.c
index 9a93762..b99bdaa 100644
--- a/src/playlist/art.c
+++ b/src/playlist/art.c
@@ -42,7 +42,7 @@
 
 static void ArtCacheCreateDir( const char *psz_dir )
 {
-    char newdir[strlen( psz_dir ) + 1];
+    char* newdir = alloca( sizeof(*newdir) * ( strlen( psz_dir ) + 1 ) );
     strcpy( newdir, psz_dir );
     char * psz_newdir = newdir;
     char * psz = psz_newdir;
diff --git a/src/playlist/loadsave.c b/src/playlist/loadsave.c
index 85a3e9e..1271b30 100644
--- a/src/playlist/loadsave.c
+++ b/src/playlist/loadsave.c
@@ -191,7 +191,7 @@ int playlist_MLDump( playlist_t *p_playlist )
         return VLC_EGENERIC;
     }
 
-    char psz_dirname[ strlen( psz_datadir ) + sizeof( DIR_SEP "ml.xspf")];
+    char* psz_dirname = alloca( sizeof(*psz_dirname) * ( strlen(psz_datadir) + sizeof(DIR_SEP "ml.xspf") ) );
     strcpy( psz_dirname, psz_datadir );
     free( psz_datadir );
     if( config_CreateDir( (vlc_object_t *)p_playlist, psz_dirname ) )
diff --git a/src/stream_output/sdp.c b/src/stream_output/sdp.c
index 37c55b0..fd7e7ff 100644
--- a/src/stream_output/sdp.c
+++ b/src/stream_output/sdp.c
@@ -267,7 +267,7 @@ char *vlc_sdp_Start (vlc_object_t *obj, const char *cfgpref,
     if (cfglen > 100)
         return NULL;
 
-    char varname[cfglen + sizeof ("description")], *subvar = varname + cfglen;
+    char* varname = alloca( sizeof(*varname) * ( cfglen + sizeof ("description") ) ), *subvar = varname + cfglen;
     strcpy (varname, cfgpref);
 
     strcpy (subvar, "name");
diff --git a/src/test/xmlent.c b/src/test/xmlent.c
index 6c04093..b5ba288 100644
--- a/src/test/xmlent.c
+++ b/src/test/xmlent.c
@@ -31,7 +31,7 @@
 
 static void decode (const char *in, const char *out)
 {
-    char buf[strlen (in) + 1];
+	char* buf = alloca(sizeof(*buf) * (strlen(in) + 1));
 
     printf ("\"%s\" -> \"%s\" ?\n", in, out);
     strcpy (buf, in);
-- 
1.7.9




More information about the vlc-devel mailing list