diff options
author | Simo Sorce <idra@samba.org> | 2001-11-18 16:12:11 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2001-11-18 16:12:11 +0000 |
commit | 60906f657cb070929e96b4c81b8e24bae3a4ed61 (patch) | |
tree | 735931984fa77caf8b174623eb18db5b0a321b5e /source3/lib/util_str.c | |
parent | 15ca82215e015149b4ac9ac7df96a081741ef37a (diff) | |
download | samba-60906f657cb070929e96b4c81b8e24bae3a4ed61.tar.gz samba-60906f657cb070929e96b4c81b8e24bae3a4ed61.tar.bz2 samba-60906f657cb070929e96b4c81b8e24bae3a4ed61.zip |
fixed some bugs.
(This used to be commit 37edaeddce09193450b18b1b85aa41960cb39741)
Diffstat (limited to 'source3/lib/util_str.c')
-rw-r--r-- | source3/lib/util_str.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 4c17d1f08b..d7e6fa0781 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -753,18 +753,18 @@ smb_ucs2_t *all_string_sub_w(smb_ucs2_t *s, const smb_ucs2_t *pattern, const smb_ucs2_t *insert) { smb_ucs2_t *r, *rp, *sp; - size_t ls, lp, li, lt; + size_t lr, lp, li, lt; if (!insert || !pattern || !*pattern || !s) return NULL; - ls = lt = (size_t)strlen_w(s) * sizeof(smb_ucs2_t); - lp = (size_t)strlen_w(pattern) * sizeof(smb_ucs2_t); - li = (size_t)strlen_w(insert) * sizeof(smb_ucs2_t); + lt = (size_t)strlen_w(s); + lp = (size_t)strlen_w(pattern); + li = (size_t)strlen_w(insert); if (li > lp) { smb_ucs2_t *st = s; int ld = li - lp; - while (sp = strstr_w(st, pattern)) { + while ((sp = strstr_w(st, pattern))) { st = sp + lp; lt += ld; } @@ -776,13 +776,18 @@ smb_ucs2_t *all_string_sub_w(smb_ucs2_t *s, const smb_ucs2_t *pattern, return NULL; } - while (sp = strstr_w(s, pattern)) { - memcpy(rp, s, sp - s); - rp += (sp - s); - memcpy(rp, insert, li); + while ((sp = strstr_w(s, pattern))) { + memcpy(rp, s, (sp - s)); + rp += ((sp - s) / sizeof(smb_ucs2_t)); + memcpy(rp, insert, (li * sizeof(smb_ucs2_t))); s = sp + lp; rp += li; } + lr = ((rp - r) / sizeof(smb_ucs2_t)); + if (lr < lt) { + memcpy(rp, s, ((lt - lr) * sizeof(smb_ucs2_t))); + rp += (lt - lr); + } *rp = 0; return r; |