summaryrefslogtreecommitdiff
path: root/src/common/extstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/extstr.c')
-rw-r--r--src/common/extstr.c24
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;
}