]> git.sesse.net Git - vlc/blobdiff - modules/demux/nuv.c
Replace argument = realloc( argument, size ); with realloc_or_free() in modules/...
[vlc] / modules / demux / nuv.c
index 38ccecd63c304d500dc7a399c9b8a3f65dcc25bb..31abc9765dabec184f94fa52bee09f3d3371c01e 100644 (file)
@@ -32,6 +32,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_demux.h>
+#include <vlc_memory.h>
 
 /* TODO:
  *  - test
 static int  Open  ( vlc_object_t * );
 static void Close ( vlc_object_t * );
 
-vlc_module_begin();
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_DEMUX );
-    set_description( N_("Nuv demuxer") );
-    set_capability( "demux", 145 );
-    set_callbacks( Open, Close );
-    add_shortcut( "nuv" );
-vlc_module_end();
+vlc_module_begin ()
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_DEMUX )
+    set_description( N_("Nuv demuxer") )
+    set_capability( "demux", 145 )
+    set_callbacks( Open, Close )
+    add_shortcut( "nuv" )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -314,7 +315,7 @@ static int Open( vlc_object_t * p_this )
     {
         es_format_t fmt;
 
-        es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC('m','p','g','a') );
+        es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_MPGA );
         fmt.audio.i_rate = p_sys->exh.i_audio_sample_rate;
         fmt.audio.i_bitspersample = p_sys->exh.i_audio_bits_per_sample;
 
@@ -461,9 +462,14 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             {
                 i64 = stream_Size( p_demux->s );
                 if( i64 > 0 )
-                    *pf = (double)stream_Tell( p_demux->s ) / (double)i64;
+                {
+                    const double f_current = stream_Tell( p_demux->s );
+                    *pf = f_current / (double)i64;
+                }
                 else
+                {
                     *pf = 0.0;
+                }
             }
             return VLC_SUCCESS;
 
@@ -723,9 +729,6 @@ static int SeekTableLoad( demux_t *p_demux, demux_sys_t *p_sys )
 {
     frame_header_t fh;
     int64_t i_original_pos;
-    uint8_t* p_seek_table;
-    uint8_t* p_kfa_table;
-    int32_t i_seek_elements = 0, i_kfa_elements = 0, j;
     int64_t i_time, i_offset;
     int keyframe, last_keyframe = 0, frame = 0, kfa_entry_id = 0;
 
@@ -745,29 +748,29 @@ static int SeekTableLoad( demux_t *p_demux, demux_sys_t *p_sys )
     if( FrameHeaderLoad( p_demux, &fh ) )
         return VLC_EGENERIC;
 
-    if( fh.i_type == 'Q' )
-    {
-        p_seek_table = malloc( fh.i_length );
-        if( p_seek_table == NULL )
-            return VLC_ENOMEM;
-
-        if( stream_Read( p_demux->s, p_seek_table, fh.i_length ) != fh.i_length )
-        {
-            free( p_seek_table );
-            return VLC_EGENERIC;
-        }
-
-        i_seek_elements = fh.i_length / 12;
-    }
-    else
+    if( fh.i_type != 'Q' )
     {
         msg_Warn( p_demux, "invalid seektable, frame type=%c", fh.i_type );
         stream_Seek( p_demux->s, i_original_pos );
         return VLC_EGENERIC;
     }
 
+    /* */
+    uint8_t *p_seek_table = malloc( fh.i_length );
+    if( p_seek_table == NULL )
+        return VLC_ENOMEM;
+
+    if( stream_Read( p_demux->s, p_seek_table, fh.i_length ) != fh.i_length )
+    {
+        free( p_seek_table );
+        return VLC_EGENERIC;
+    }
+    const int32_t i_seek_elements = fh.i_length / 12;
 
     /* Get keyframe adjust offsets */
+    int32_t i_kfa_elements;
+    uint8_t *p_kfa_table;
+
     if( p_sys->exh.i_keyframe_adjust_offset > 0 )
     {
         msg_Dbg( p_demux, "seeking in stream to %"PRIi64, p_sys->exh.i_keyframe_adjust_offset );
@@ -787,7 +790,7 @@ static int SeekTableLoad( demux_t *p_demux, demux_sys_t *p_sys )
         {
             p_kfa_table = malloc( fh.i_length );
 
-            if( p_seek_table == NULL )
+            if( p_kfa_table == NULL )
             {
                 free( p_seek_table );
                 return VLC_ENOMEM;
@@ -803,12 +806,16 @@ static int SeekTableLoad( demux_t *p_demux, demux_sys_t *p_sys )
             i_kfa_elements = fh.i_length / 8;
         }
     }
+    else
+    {
+        i_kfa_elements = 0;
+    }
 
 
     if( i_kfa_elements > 0 )
         msg_Warn( p_demux, "untested keyframe adjust support, upload samples" );
 
-    for(j=0; j < i_seek_elements; j++)
+    for( int32_t j = 0; j < i_seek_elements; j++)
     {
 #if 0
         uint8_t* p = p_seek_table + j * 12;
@@ -917,8 +924,9 @@ static void demux_IndexAppend( demux_index_t *p_idx,
         else
         {
             p_idx->i_idx_max += 1000;
-            p_idx->idx = realloc( p_idx->idx,
-                                  p_idx->i_idx_max*sizeof(demux_index_entry_t));
+            p_idx->idx = realloc_or_free( p_idx->idx,
+                                p_idx->i_idx_max*sizeof(demux_index_entry_t));
+            assert( p_idx->idx );
         }
     }