libvlc: media: remove flexible array member
authorThomas Guillem <git@videolan.org>
Fri, 20 May 2016 08:33:23 +0000 (10:33 +0200)
committerThomas Guillem <thomas@gllm.fr>
Tue, 24 May 2016 09:38:08 +0000 (11:38 +0200)
Because ISO C++ has no notation of flexible arrays and this a public header.

include/vlc/libvlc_media.h
lib/media.c

index 173c78a..bd8a9c4 100644 (file)
@@ -286,9 +286,9 @@ typedef enum
  */
 typedef struct
 {
+    char *                          psz_uri;
     libvlc_media_slave_type_t       i_type;
     unsigned int                    i_priority;
-    char                            psz_uri[];
 } libvlc_media_slave_t;
 
 /**
index c11f8f9..7d47a9e 100644 (file)
@@ -1164,15 +1164,16 @@ unsigned int libvlc_media_slaves_get( libvlc_media_t *p_md,
         input_item_slave_t *p_item_slave = p_input_item->pp_slaves[i];
         assert( p_item_slave->i_priority >= SLAVE_PRIORITY_MATCH_NONE );
 
+        /* also allocate psz_uri buffer at the end of the struct */
         libvlc_media_slave_t *p_slave = malloc( sizeof(*p_slave) +
                                                 strlen( p_item_slave->psz_uri )
                                                 + 1 );
-
         if( p_slave == NULL )
         {
             libvlc_media_slaves_release(pp_slaves, i);
             return vlc_mutex_unlock( &p_input_item->lock ), 0;
         }
+        p_slave->psz_uri = (char *) ((uint8_t *)p_slave) + sizeof(*p_slave);
         strcpy( p_slave->psz_uri, p_item_slave->psz_uri );
 
         switch( p_item_slave->i_type )