#include <errno.h>
#include <sys/types.h>
+#include <limits.h>
#include <vlc_demux.h>
#include <vlc_charset.h>
static int Open ( vlc_object_t *p_this );
static void Close( vlc_object_t *p_this );
-vlc_module_begin();
- set_description( N_("Vobsub subtitles parser") );
- set_category( CAT_INPUT );
- set_subcategory( SUBCAT_INPUT_DEMUX );
- set_capability( "demux", 1 );
+vlc_module_begin ()
+ set_description( N_("Vobsub subtitles parser") )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_DEMUX )
+ set_capability( "demux", 1 )
- set_callbacks( Open, Close );
+ set_callbacks( Open, Close )
- add_shortcut( "vobsub" );
- add_shortcut( "subtitle" );
-vlc_module_end();
+ add_shortcut( "vobsub" )
+ add_shortcut( "subtitle" )
+vlc_module_end ()
/*****************************************************************************
* Prototypes:
static int TextLoad( text_t *txt, stream_t *s )
{
- int i_line_max;
-
- /* init txt */
- i_line_max = 500;
- txt->i_line_count = 0;
- txt->i_line = 0;
- txt->line = calloc( i_line_max, sizeof( char * ) );
- if( !txt->line )
- return VLC_EGENERIC;
+ char **lines = NULL;
+ size_t n = 0;
/* load the complete file */
for( ;; )
{
char *psz = stream_ReadLine( s );
+ char **ppsz_new;
- if( psz == NULL )
+ if( psz == NULL || (n >= INT_MAX/sizeof(char *)) )
break;
- txt->line[txt->i_line_count++] = psz;
- if( txt->i_line_count >= i_line_max )
+ ppsz_new = realloc( lines, (n + 1) * sizeof (char *) );
+ if( ppsz_new == NULL )
{
- char **ppsz_old = txt->line;
-
- i_line_max += 100;
- txt->line = realloc( txt->line, i_line_max * sizeof( char*) );
- if( !txt->line )
- {
- free( ppsz_old );
- break;
- }
+ free( psz );
+ break;
}
+ lines = ppsz_new;
+ lines[n++] = psz;
}
- if( txt->i_line_count <= 0 )
- {
- free( txt->line );
- return VLC_EGENERIC;
- }
+ txt->i_line_count = n;
+ txt->i_line = 0;
+ txt->line = lines;
return VLC_SUCCESS;
}
+
static void TextUnload( text_t *txt )
{
int i;