]> git.sesse.net Git - vlc/commitdiff
- Save one malloc()
authorRémi Denis-Courmont <rem@videolan.org>
Mon, 1 May 2006 15:18:01 +0000 (15:18 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Mon, 1 May 2006 15:18:01 +0000 (15:18 +0000)
- Return NULL in case of error

src/misc/unicode.c

index e7c4e41811877a1b02cfc4c8c6605feeeef802aa..5fa1b1c5fc36a6a5b91634191935825673149f63 100644 (file)
@@ -140,18 +140,18 @@ static char *MB2MB( const char *string, UINT fromCP, UINT toCP )
     int len;
 
     len = MultiByteToWideChar( fromCP, 0, string, -1, NULL, 0 );
-    assert( len > 0 );
-    wide = (wchar_t *)malloc (len * sizeof (wchar_t));
-    if( wide == NULL )
+    if( len == 0 );
         return NULL;
 
+    wchar_t wide[len];
+
     MultiByteToWideChar( fromCP, 0, string, -1, wide, len );
     len = WideCharToMultiByte( toCP, 0, wide, -1, NULL, 0, NULL, NULL );
-    assert( len > 0 );
+    if( len == 0 )
+        return NULL;
     out = malloc( len );
 
     WideCharToMultiByte( toCP, 0, wide, -1, out, len, NULL, NULL );
-    free( wide );
     return out;
 }
 #endif