Commit 5c7ef93f authored by Laurent Aimar's avatar Laurent Aimar

Improved a bit SRT support.

Added missings realloc/malloc checks.
Added support for not closed html tags (only if missing at the end).
parent f4ad83ef
...@@ -598,24 +598,26 @@ static void HtmlCopy( char **ppsz_html, char **ppsz_subtitle, const char *psz_te ...@@ -598,24 +598,26 @@ static void HtmlCopy( char **ppsz_html, char **ppsz_subtitle, const char *psz_te
static char *CreateHtmlSubtitle( int *pi_align, char *psz_subtitle ) static char *CreateHtmlSubtitle( int *pi_align, char *psz_subtitle )
{ {
char *psz_tag = malloc( ( strlen( psz_subtitle ) / 3 ) + 1 ); /* */
if( !psz_tag ) return NULL; char *psz_tag = malloc( ( strlen( psz_subtitle ) / 3 ) + 1 );
size_t i_buf_size = strlen( psz_subtitle ) + 100; if( !psz_tag )
char *psz_html_start = malloc( i_buf_size ); return NULL;
bool b_has_align = false;
psz_tag[ 0 ] = '\0'; psz_tag[ 0 ] = '\0';
/* */
size_t i_buf_size = strlen( psz_subtitle ) + 100;
char *psz_html_start = malloc( i_buf_size );
char *psz_html = psz_html_start;
if( psz_html_start == NULL ) if( psz_html_start == NULL )
{ {
free( psz_tag ); free( psz_tag );
return NULL; return NULL;
} }
psz_html[0] = '\0';
char *psz_html = psz_html_start;
strcpy( psz_html, "<text>" ); bool b_has_align = false;
psz_html += 6;
HtmlPut( &psz_html, "<text>" );
/* */ /* */
while( *psz_subtitle ) while( *psz_subtitle )
...@@ -877,27 +879,58 @@ static char *CreateHtmlSubtitle( int *pi_align, char *psz_subtitle ) ...@@ -877,27 +879,58 @@ static char *CreateHtmlSubtitle( int *pi_align, char *psz_subtitle )
if( ( size_t )( psz_html - psz_html_start ) > i_buf_size - 50 ) if( ( size_t )( psz_html - psz_html_start ) > i_buf_size - 50 )
{ {
int i_len = psz_html - psz_html_start; const int i_len = psz_html - psz_html_start;
i_buf_size += 200; i_buf_size += 200;
psz_html_start = realloc( psz_html_start, i_buf_size ); char *psz_new = realloc( psz_html_start, i_buf_size );
psz_html = psz_html_start + i_len; if( !psz_new )
*psz_html = '\0'; break;
psz_html_start = psz_new;
psz_html = &psz_new[i_len];
} }
} }
strcpy( psz_html, "</text>" ); if( psz_html_start )
psz_html += 7;
if( psz_tag[ 0 ] != '\0' )
{ {
/* Not well formed -- kill everything */ static const char *psz_text_close = "</text>";
free( psz_html_start ); static const char *psz_tag_long = "/font>";
psz_html_start = NULL;
} /* Realloc for closing tags and shrink memory */
else if( psz_html_start ) const size_t i_length = (size_t)( psz_html - psz_html_start );
{
/* Shrink the memory requirements */ const size_t i_size = i_length + strlen(psz_tag_long) * strlen(psz_tag) + strlen(psz_text_close) + 1;
psz_html_start = realloc( psz_html_start, psz_html - psz_html_start + 1 ); char *psz_new = realloc( psz_html_start, i_size );
if( psz_new )
{
psz_html_start = psz_new;
psz_html = &psz_new[i_length];
/* Close not well formed subtitle */
while( *psz_tag )
{
/* */
char *psz_last = &psz_tag[strlen(psz_tag)-1];
switch( *psz_last )
{
case 'b':
HtmlPut( &psz_html, "</b>" );
break;
case 'i':
HtmlPut( &psz_html, "</i>" );
break;
case 'u':
HtmlPut( &psz_html, "</u>" );
break;
case 'f':
HtmlPut( &psz_html, "/font>" );
break;
case 'I':
break;
}
*psz_last = '\0';
}
HtmlPut( &psz_html, psz_text_close );
}
} }
free( psz_tag ); free( psz_tag );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment