]> git.sesse.net Git - vlc/commitdiff
Win32: FromLocale/ToLocale: fix stack underflow on very long strings
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 6 Sep 2009 07:46:36 +0000 (10:46 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 6 Sep 2009 07:48:26 +0000 (10:48 +0300)
src/text/unicode.c

index bcc1029a93d51f17b56b58b8eb730a32be06b577..0a36671a4ecbe84052d8494f8957df837ec2a475 100644 (file)
@@ -118,17 +118,18 @@ static char *locale_fast (const char *string, bool from)
 
     len = 1 + MultiByteToWideChar (from ? CP_ACP : CP_UTF8,
                                    0, string, -1, NULL, 0);
-    wchar_t wide[len];
+    wchar_t *wide = malloc (len * sizeof (wchar_t));
+    if (wide == NULL)
+        return NULL;
 
     MultiByteToWideChar (from ? CP_ACP : CP_UTF8, 0, string, -1, wide, len);
     len = 1 + WideCharToMultiByte (from ? CP_UTF8 : CP_ACP, 0, wide, -1,
                                    NULL, 0, NULL, NULL);
     out = malloc (len);
-    if (out == NULL)
-        return NULL;
-
-    WideCharToMultiByte (from ? CP_UTF8 : CP_ACP, 0, wide, -1, out, len,
-                         NULL, NULL);
+    if (out != NULL)
+        WideCharToMultiByte (from ? CP_UTF8 : CP_ACP, 0, wide, -1, out, len,
+                             NULL, NULL);
+    free (wide);
     return out;
 #else
     (void)from;