This is the mail archive of the
cygwin-patches@cygwin.com
mailing list for the Cygwin project.
Re: [Patch]: Unicode length
At 09:29 AM 6/16/2004 +0200, Corinna Vinschen wrote:
>Hi Pierre,
>
>On Jun 16 00:36, Pierre A. Humblet wrote:
>> This has not yet been fully tested.
>>
>> There is a similar problem in str2buf2uni_cat and perhaps
>> elsewhere, but it's late.
>> Perhaps the debug_printf should be in sys_mbstowcs.
>>
>> Pierre
>>
>> 2004-06-16 Pierre Humblet <pierre.humblet@ieee.org>
>>
>> * security.cc (str2buf2uni): Set the unicode length from the
>> return value of sys_mbstowcs().
>
>This change looks not quite ok. The return value from MultiByteToWideChar
>is the "number of wide characters" while Length and MaximumLength in a
>UNICODE_STRING are defined to contain "the length in bytes".
Right, that's why the return value is multiplied by sizeof (WCHAR), as in
+ tgt.MaximumLength = sys_mbstowcs (buf, srcstr, strlen (srcstr) + 1) * sizeof (WCHAR);
After sleeping over it I see other issues. An accented string can have several
unicode representations, e.g. with composite characters or with precomposed
characters. Do you know if NT prefers or insists on one or the other for filenames?
If it uses composite characters we should pass the right flag to MultiByteToWideChar.
Also in that case (and perhaps others ?) the unicode string can be longer (in wchar)
than the original string (in char). It would be necessary to pass the maximum unicode
length to str2buf2uni, instead of assuming it is strlen (srcstr) + 1.
Pierre