1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-10 12:58:35 +03:00

fixed some bugs.

(This used to be commit 37edaeddce09193450b18b1b85aa41960cb39741)
This commit is contained in:
Simo Sorce 2001-11-18 16:12:11 +00:00
parent 15ca82215e
commit 60906f657c
2 changed files with 19 additions and 18 deletions

View File

@ -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;

View File

@ -3,6 +3,7 @@
Version 3.0
Samba utility functions
Copyright (C) Andrew Tridgell 1992-2001
Copyright (C) Simo Sorce 2001
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -476,6 +477,7 @@ smb_ucs2_t *strcat_w(smb_ucs2_t *dest, const smb_ucs2_t *src)
return dest;
}
/*******************************************************************
replace any occurence of oldc with newc in unicode string
********************************************************************/
@ -495,7 +497,7 @@ BOOL trim_string_w(smb_ucs2_t *s, const smb_ucs2_t *front,
const smb_ucs2_t *back)
{
BOOL ret = False;
size_t len, lw, front_len, flw, back_len, blw;
size_t len, front_len, back_len;
if (!s || !*s) return False;
@ -503,24 +505,18 @@ BOOL trim_string_w(smb_ucs2_t *s, const smb_ucs2_t *front,
if (front && *front) {
front_len = strlen_w(front);
flw = front_len * sizeof(smb_ucs2_t);
lw = (len + 1) * sizeof(smb_ucs2_t);
while (len && strncmp_w(s, front, front_len) == 0) {
memcpy(s, s + flw, lw - flw);
memmove(s, (s + front_len), (len - front_len + 1) * sizeof(smb_ucs2_t));
len -= front_len;
lw -= flw;
ret = True;
}
}
if (back && *back) {
back_len = strlen_w(back);
blw = back_len * sizeof(smb_ucs2_t);
lw = len * sizeof(smb_ucs2_t);
while (len && strncmp_w(s + lw - blw, back, back_len) == 0) {
while (len && strncmp_w((s + (len - back_len)), back, back_len) == 0) {
s[len - back_len] = 0;
len -= back_len;
lw -= blw;
ret = True;
}
}