]> git.sesse.net Git - vlc/commitdiff
Fixed segfault in freetype after ToCharset() changes.
authorLaurent Aimar <fenrir@videolan.org>
Wed, 3 Nov 2010 23:07:37 +0000 (00:07 +0100)
committerLaurent Aimar <fenrir@videolan.org>
Wed, 3 Nov 2010 23:09:51 +0000 (00:09 +0100)
The code is quite ugly and the comments in IconvText() where wrongs...

modules/misc/freetype.c

index 2d376497360a1ab68a6586c3c9156f9e78b6d9fe..a32598143b661d3bd7bb754ada45bf314ed0eb2c 100644 (file)
@@ -1351,30 +1351,26 @@ static bool StyleEquals( ft_style_t *s1, ft_style_t *s2 )
 static void IconvText( filter_t *p_filter, const char *psz_string,
                        size_t *i_string_length, uint32_t **ppsz_unicode )
 {
-    /* If memory hasn't been allocated for our output string, allocate it here
-     * - the calling function must now be responsible for freeing it.
-     */
-    if( !*ppsz_unicode )
-        *ppsz_unicode = (uint32_t *)
-            malloc( (strlen( psz_string ) + 1) * sizeof( uint32_t ));
-
-    /* We don't need to handle a NULL pointer in *ppsz_unicode
-     * if we are instead testing for a non NULL value like we are here */
+    *i_string_length = 0;
+    if( *ppsz_unicode == NULL )
+        return;
 
-    if( *ppsz_unicode )
-    {
-        *ppsz_unicode =
+    size_t i_length;
+    uint32_t *psz_tmp =
 #if defined(WORDS_BIGENDIAN)
-            ToCharset( "UCS-4BE", psz_string, i_string_length );
+            ToCharset( "UCS-4BE", psz_string, &i_length );
 #else
-            ToCharset( "UCS-4LE", psz_string, i_string_length );
+            ToCharset( "UCS-4LE", psz_string, &i_length );
 #endif
-        if( *ppsz_unicode != NULL )
-            *i_string_length /= 4;
-        else
-            /* FIXME: This is going to fail miserably in the caller */
-            msg_Warn( p_filter, "failed to convert string to unicode (%m)" );
+    if( !psz_tmp )
+    {
+        msg_Warn( p_filter, "failed to convert string to unicode (%m)" );
+        return;
     }
+    memcpy( *ppsz_unicode, psz_tmp, i_length );
+    *i_string_length = i_length / 4;
+
+    free( psz_tmp );
 }
 
 static ft_style_t *GetStyleFromFontStack( filter_sys_t *p_sys,