summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-12-15 21:59:08 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-12-15 21:59:08 (GMT)
commitd2aee5bdde7ca64fc4bb8553d98cc7d2ac92c5e5 (patch)
tree028835a80d0ec571d0d62cfe941b6c95ddf7996a /src
parentece6eb62458f0222f769741ce123eadde07b017c (diff)
Fixed a bug when replacing strings.
Diffstat (limited to 'src')
-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;
}