[PATCH] ntdll: Don't use WCHAR in unix_to_win_locale().
Jefferson Carpenter
jeffersoncarpenter2 at gmail.com
Wed Jul 1 06:27:29 CDT 2020
This seems to have caused new branches on uninitialized values:
https://bugs.winehq.org/show_bug.cgi?id=49494
On 6/30/2020 2:44 PM, Gijs Vermeulen wrote:
> Signed-off-by: Gijs Vermeulen <gijsvrm at gmail.com>
> ---
> dlls/ntdll/unix/env.c | 49 +++++++++++++++++--------------------------
> 1 file changed, 19 insertions(+), 30 deletions(-)
>
> diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c
> index e260e5c338..e57b625689 100644
> --- a/dlls/ntdll/unix/env.c
> +++ b/dlls/ntdll/unix/env.c
> @@ -74,8 +74,8 @@ char **main_envp = NULL;
> static WCHAR **main_wargv;
>
> static CPTABLEINFO unix_table;
> -static WCHAR system_locale[LOCALE_NAME_MAX_LENGTH];
> -static WCHAR user_locale[LOCALE_NAME_MAX_LENGTH];
> +static char system_locale[LOCALE_NAME_MAX_LENGTH];
> +static char user_locale[LOCALE_NAME_MAX_LENGTH];
>
> static void *read_nls_file( const char *name )
> {
> @@ -649,18 +649,11 @@ static WCHAR **build_wargv( char **argv )
>
> /* Unix format is: lang[_country][.charset][@modifier]
> * Windows format is: lang[-script][-country][_modifier] */
> -static BOOL unix_to_win_locale( const char *unix_name, WCHAR *win_name )
> +static BOOL unix_to_win_locale( const char *unix_name, char *win_name )
> {
> - static const WCHAR sepW[] = {'_','.','@',0};
> - static const WCHAR posixW[] = {'P','O','S','I','X',0};
> - static const WCHAR cW[] = {'C',0};
> - static const WCHAR euroW[] = {'e','u','r','o',0};
> - static const WCHAR latinW[] = {'l','a','t','i','n',0};
> - static const WCHAR latnW[] = {'-','L','a','t','n',0};
> - static const WCHAR enUSW[] = {'e','n','-','U','S',0};
> - WCHAR buffer[LOCALE_NAME_MAX_LENGTH];
> - WCHAR *p, *country = NULL, *modifier = NULL;
> - DWORD len;
> + static const char sep[] = "_.@";
> + char buffer[LOCALE_NAME_MAX_LENGTH];
> + char *p, *country = NULL, *modifier = NULL;
>
> if (!unix_name || !unix_name[0] || !strcmp( unix_name, "C" ))
> {
> @@ -668,16 +661,12 @@ static BOOL unix_to_win_locale( const char *unix_name, WCHAR *win_name )
> if (!unix_name || !unix_name[0]) return FALSE;
> }
>
> - len = ntdll_umbstowcs( unix_name, strlen(unix_name), buffer, ARRAY_SIZE(buffer) );
> - if (len == ARRAY_SIZE(buffer)) return FALSE;
> - buffer[len] = 0;
> -
> - if (!(p = wcspbrk( buffer, sepW )))
> + if (!(p = strpbrk( buffer, sep )))
> {
> - if (!wcscmp( buffer, posixW ) || !wcscmp( buffer, cW ))
> - wcscpy( win_name, enUSW );
> + if (!strcmp( buffer, "POSIX" ) || !strcmp( buffer, "C" ))
> + strcpy( win_name, "en-US" );
> else
> - wcscpy( win_name, buffer );
> + strcpy( win_name, buffer );
> return TRUE;
> }
>
> @@ -685,13 +674,13 @@ static BOOL unix_to_win_locale( const char *unix_name, WCHAR *win_name )
> {
> *p++ = 0;
> country = p;
> - p = wcspbrk( p, sepW + 1 );
> + p = strpbrk( p, sep + 1 );
> }
> if (p && *p == '.')
> {
> *p++ = 0;
> /* charset, ignore */
> - p = wcschr( p, '@' );
> + p = strchr( p, '@' );
> }
> if (p)
> {
> @@ -701,18 +690,18 @@ static BOOL unix_to_win_locale( const char *unix_name, WCHAR *win_name )
>
> /* rebuild a Windows name */
>
> - wcscpy( win_name, buffer );
> + strcpy( win_name, buffer );
> if (modifier)
> {
> - if (!wcscmp( modifier, latinW )) wcscat( win_name, latnW );
> - else if (!wcscmp( modifier, euroW )) {} /* ignore */
> + if (!strcmp( modifier, "latin" )) strcat( win_name, "-Latn" );
> + else if (!strcmp( modifier, "euro" )) {} /* ignore */
> else return FALSE;
> }
> if (country)
> {
> - p = win_name + wcslen(win_name);
> + p = win_name + strlen(win_name);
> *p++ = '-';
> - wcscpy( p, country );
> + strcpy( p, country );
> }
> return TRUE;
> }
> @@ -1083,6 +1072,6 @@ void CDECL get_unix_codepage( CPTABLEINFO *table )
> */
> void CDECL get_locales( WCHAR *sys, WCHAR *user )
> {
> - wcscpy( sys, system_locale );
> - wcscpy( user, user_locale );
> + ntdll_umbstowcs( system_locale, ARRAY_SIZE(system_locale), sys, LOCALE_NAME_MAX_LENGTH * sizeof(WCHAR) );
> + ntdll_umbstowcs( user_locale, ARRAY_SIZE(user_locale), user, LOCALE_NAME_MAX_LENGTH * sizeof(WCHAR) );
> }
>
More information about the wine-devel
mailing list