This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch]: Unicode length


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".


Corinna



> Index: security.cc
> ===================================================================
> RCS file: /cvs/src/src/winsup/cygwin/security.cc,v
> retrieving revision 1.172
> diff -u -p -r1.172 security.cc
> --- security.cc 28 May 2004 19:50:06 -0000      1.172
> +++ security.cc 16 Jun 2004 04:28:10 -0000
> @@ -156,13 +156,21 @@ str2buf2lsa (LSA_STRING &tgt, char *buf,
>    memcpy (buf, srcstr, tgt.MaximumLength);
>  }
>  
> +/* The dimension of buf is assumed to be at least strlen(srcstr) + 1,
> +   The result will be shorter if the input has multibyte chars */
>  void
>  str2buf2uni (UNICODE_STRING &tgt, WCHAR *buf, const char *srcstr)
>  {
> -  tgt.Length = strlen (srcstr) * sizeof (WCHAR);
> -  tgt.MaximumLength = tgt.Length + sizeof (WCHAR);
> +  tgt.MaximumLength = sys_mbstowcs (buf, srcstr, strlen (srcstr) + 1) * sizeof (WCHAR);
> +  if (tgt.MaximumLength)
> +    tgt.Length = tgt.MaximumLength - sizeof (WCHAR);
> +  else
> +    {
> +      debug_printf ("sys_mbstowcs: %E");
> +      tgt.Length = 0;
> +    }
>    tgt.Buffer = (PWCHAR) buf;
> -  sys_mbstowcs (buf, srcstr, tgt.MaximumLength);
> +
>  }
>  
>  void

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Co-Project Leader          mailto:cygwin@cygwin.com
Red Hat, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]