From 0f52459b725a3c7df744c4b788a16154972d4a95 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 6 Sep 2009 10:46:36 +0300 Subject: [PATCH] Win32: FromLocale/ToLocale: fix stack underflow on very long strings --- src/text/unicode.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/text/unicode.c b/src/text/unicode.c index bcc1029a93..0a36671a4e 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; -- 2.39.2