summaryrefslogtreecommitdiff
path: root/source/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-06-12 18:20:26 +0000
committerJeremy Allison <jra@samba.org>2001-06-12 18:20:26 +0000
commit24eea8a309ff0151277b9537a5c00321041e70d3 (patch)
treebc2dd6f64d055d524647576defe4356ad4a2b205 /source/lib
parent4d2f6605820f7b62ff1a748952fd6edad63c1213 (diff)
downloadsamba-24eea8a309ff0151277b9537a5c00321041e70d3.tar.gz
Fix from TAKAHASHI Motonobu <monyo@samba.gr.jp> for multibyte conversion
problems. Jeremy.
Diffstat (limited to 'source/lib')
-rw-r--r--source/lib/util_unistr.c46
1 files changed, 16 insertions, 30 deletions
diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c
index 18f3b54bf71..f6bb7e80681 100644
--- a/source/lib/util_unistr.c
+++ b/source/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.
********************************************************************/