diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/extstr.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/common/extstr.c b/src/common/extstr.c index 0b37606..2e69e3f 100644 --- a/src/common/extstr.c +++ b/src/common/extstr.c @@ -189,21 +189,25 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2) { index = found - haystack; - if (len1 != len2) + if (len2 > len1) { - if (len2 > len1) - inlen += len2 - len1; - - else - inlen -= len1 - len2; + inlen += (len2 - len1); haystack = (char *)realloc(haystack, inlen * sizeof(char *)); found = haystack + index; - if (len2 > len1) - memmove(found + len2, found + len1, inlen - len1 - (found - haystack)); - else - memmove(found + len1, found + len2, inlen - len1 - (found - haystack)); + memmove(found + len1, found + len2, inlen - index + len2); + + } + + else if (len2 < len1) + { + memmove(found + len2, found + len1, inlen - index - len1); + + inlen -= (len1 - len2); + + haystack = (char *)realloc(haystack, inlen * sizeof(char *)); + found = haystack + index; } |