diff options
author | Jeremy Allison <jra@samba.org> | 2001-06-12 18:20:26 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2001-06-12 18:20:26 +0000 |
commit | 4248d14ff65201298f60546b318a776590d08dfc (patch) | |
tree | 2b0c760eec6f4c4d047d9daea1b0f7f2bd86f264 /source3/lib | |
parent | c569e20b1071e5e1e6815e102ae0f5ab5710ee0a (diff) | |
download | samba-4248d14ff65201298f60546b318a776590d08dfc.tar.gz samba-4248d14ff65201298f60546b318a776590d08dfc.tar.bz2 samba-4248d14ff65201298f60546b318a776590d08dfc.zip |
Fix from TAKAHASHI Motonobu <monyo@samba.gr.jp> for multibyte conversion
problems.
Jeremy.
(This used to be commit 24eea8a309ff0151277b9537a5c00321041e70d3)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/util_unistr.c | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 18f3b54bf7..f6bb7e8068 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -201,11 +201,10 @@ char *dos_unistr2_to_str(UNISTR2 *str) char *lbuf = lbufs[nexti]; char *p; uint16 *src = str->buffer; - int max_size = MIN(MAXUNI-3, str->uni_str_len); nexti = (nexti+1)%8; - for (p = lbuf; (p-lbuf < max_size) && *src; src++) { + for (p = lbuf; (p - lbuf < MAXUNI-3) && (src - str->buffer < str->uni_str_len) && *src; src++) { uint16 ucs2_val = SVAL(src,0); uint16 cp_val = ucs2_to_doscp[ucs2_val]; @@ -227,49 +226,41 @@ char *dos_unistr2_to_str(UNISTR2 *str) ********************************************************************/ void ascii_to_unistr(uint16 *dest, const char *src, int maxlen) { - uint16 *destend = dest + maxlen; - register char c; + uint16 *destend = dest + maxlen; + char c; - while (dest < destend) - { - c = *(src++); - if (c == 0) - { - break; - } + while (dest < destend) { + c = *(src++); + if (c == 0) + break; SSVAL(dest, 0, c); - dest++; - } + dest++; + } - *dest = 0; + *dest = 0; } - /******************************************************************* Pull an ASCII string out of a UNICODE array (uint16's). ********************************************************************/ void unistr_to_ascii(char *dest, const uint16 *src, int len) { - char *destend = dest + len; - register uint16 c; + char *destend = dest + len; + uint16 c; - if (src == NULL) - { + if (src == NULL) { *dest = '\0'; return; } /* normal code path for a valid 'src' */ - while (dest < destend) - { + while (dest < destend) { c = SVAL(src, 0); src++; if (c == 0) - { break; - } *(dest++) = (char)c; } @@ -339,11 +330,10 @@ char *dos_buffer2_to_str(BUFFER2 *str) char *lbuf = lbufs[nexti]; char *p; uint16 *src = str->buffer; - int max_size = MIN(sizeof(str->buffer)-3, str->buf_len/2); nexti = (nexti+1)%8; - for (p = lbuf; (p-lbuf < max_size) && *src; src++) { + for (p = lbuf; (p - lbuf < sizeof(str->buffer)-3) && (src - str->buffer < str->buf_len/2) && *src; src++) { uint16 ucs2_val = SVAL(src,0); uint16 cp_val = ucs2_to_doscp[ucs2_val]; @@ -368,11 +358,10 @@ char *dos_buffer2_to_multistr(BUFFER2 *str) char *lbuf = lbufs[nexti]; char *p; uint16 *src = str->buffer; - int max_size = MIN(sizeof(str->buffer)-3, str->buf_len/2); nexti = (nexti+1)%8; - for (p = lbuf; p-lbuf < max_size; src++) { + for (p = lbuf; (p - lbuf < sizeof(str->buffer)-3) && (src - str->buffer < str->buf_len/2); src++) { if (*src == 0) { *p++ = ' '; } else { @@ -481,8 +470,6 @@ int unistrcpy(char *dst, char *src) return num_wchars; } - - /******************************************************************* Free any existing maps. ********************************************************************/ @@ -505,7 +492,6 @@ static void free_maps(smb_ucs2_t **pp_cp_to_ucs2, uint16 **pp_ucs2_to_cp) } } - /******************************************************************* Build a default (null) codepage to unicode map. ********************************************************************/ |