The patch assumes that UCS2 characters are 2-bytes each. It does not make any assumptions about the widths of the Unix charset.
Thanks, Shirish On Wed, 12 Feb 2003, Ken Cross wrote: >I'm not sure that 2 is a valid assumption. We're using UTF-8 for the >Unix charset, and a multi-byte character can be as much as 6 bytes. > >Ken >________________________________ > >Ken Cross > >Network Storage Solutions >Phone 865.675.4070 ext 31 >[EMAIL PROTECTED] > >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED]] >On Behalf Of Shirish Kalele >Sent: Wednesday, February 12, 2003 1:08 PM >To: [EMAIL PROTECTED] >Subject: init_unistr2 length calculation > > >Hi, > >In init_unistr2, the string length for the UNISTR2 structure seems to be >set equal to the number of bytes occupied by the string when encoded in >the Unix charset (i.e. the value returned by strlen()). This is not >necessarily the number of characters in the string (given UTF-8 and >other variable-byte charsets). > >Shouldn't this actually be set to half the number of bytes occupied by >the string after encoding it in UCS2? Here's a patch that does this. > >Thanks, >Shirish > >Index: rpc_parse/parse_misc.c >=================================================================== >RCS file: /cvsroot/samba/source/rpc_parse/parse_misc.c,v >retrieving revision 1.94.2.8 >diff -u -r1.94.2.8 parse_misc.c >--- rpc_parse/parse_misc.c 28 Jan 2003 21:09:56 -0000 1.94.2.8 >+++ rpc_parse/parse_misc.c 11 Feb 2003 19:52:32 -0000 >@@ -889,10 +889,6 @@ > { > ZERO_STRUCTP(str); > >- /* set up string lengths. */ >- str->uni_max_len = (uint32)len; >- str->undoc = 0; >- str->uni_str_len = (uint32)len; > > if (len < MAX_UNISTRLEN) > len = MAX_UNISTRLEN; >@@ -912,7 +908,13 @@ > if (buf==NULL) > return; > >- rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE); >+ len = rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE); len >+ /= 2; >+ /* set up string lengths. */ >+ str->uni_max_len = (uint32)len; >+ str->undoc = 0; >+ str->uni_str_len = (uint32)len; >+ > } > > /** >