[vlc-devel] commit: Win32: FromLocale/ToLocale: fix stack underflow on very long strings ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Sep 6 09:49:09 CEST 2009


vlc | branch: 1.0-bugfix | Rémi Denis-Courmont <remi at remlab.net> | Sun Sep  6 10:46:36 2009 +0300| [4fb63cbbac4463d92b12886f82a0d0d619b489ef] | committer: Rémi Denis-Courmont 

Win32: FromLocale/ToLocale: fix stack underflow on very long strings

(cherry picked from commit 0f52459b725a3c7df744c4b788a16154972d4a95)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4fb63cbbac4463d92b12886f82a0d0d619b489ef
---

 src/text/unicode.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/text/unicode.c b/src/text/unicode.c
index bcc1029..0a36671 100644
--- a/src/text/unicode.c
+++ b/src/text/unicode.c
@@ -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;




More information about the vlc-devel mailing list