[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    Re: [PATCH] BSTR in typelib.c
From:       Alexandre Julliard <julliard () winehq ! com>
Date:       2000-08-28 20:46:31
[Download RAW message or body]

Francois Jacques <francoisj@macadamian.com> writes:

> @@ -614,13 +647,34 @@
>      name=TLB_Alloc((niName.namelen & 0xff) +1);
>      TLB_Read(name, (niName.namelen & 0xff), pcx, DO_NOT_SEEK);
>      name[niName.namelen & 0xff]='\0';
> -    TRACE("%s\n", debugstr_a(name));
> -    return name;
> +    
> +    {
> +      size_t lengthInChars = CRTDLL__mbslen(name);
> +      WCHAR wstring[lengthInChars * 2 + 1];
> +      ZeroMemory(wstring, sizeof(wstring));
> +    
> +      
> +      MultiByteToWideChar(CP_ACP,
> +                        MB_PRECOMPOSED | MB_ERR_INVALID_CHARS,
> +                        name,
> +                        -1,
> +                        wstring,
> +                        sizeof(wstring));
> +
> +
> +      bstr = SysAllocStringLen(wstring, lengthInChars);
> +      lengthInChars = SysStringLen(bstr);
> +      TRACE("%s %d\n", debugstr_w(bstr), lengthInChars);
> +      
> +      return bstr;
> +    }

Allocation of a variable-size buffer on the stack is not portable (not
to mention dangerous when the original string can be any length).
Also you should use MultiByteToWideChar with a 0 dstlen instead of
CRTDLL__mbslen to compute the needed size; and MB_ERR_INVALID_CHARS is
not useful if you don't check for a returned error...

-- 
Alexandre Julliard
julliard@winehq.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic