summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/extstr.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/common/extstr.c b/src/common/extstr.c
index 851401c..59d4389 100644
--- a/src/common/extstr.c
+++ b/src/common/extstr.c
@@ -174,16 +174,21 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2)
size_t inlen; /* Taille en entrée */
size_t len1; /* Taille de l'aiguille n°1 */
size_t len2; /* Taille de l'aiguille n°2 */
+ size_t index; /* Conversion en indice */
char *found; /* Position d'une trouvaille */
inlen = strlen(haystack) + 1;
len1 = strlen(needle1);
len2 = strlen(needle2);
- for (found = strstr(haystack, needle1);
+ index = 0;
+
+ for (found = strstr(haystack + index, needle1);
found != NULL;
- found = strstr(haystack, needle1))
+ found = strstr(haystack + index, needle1))
{
+ index = found - haystack;
+
if (len1 != len2)
{
if (len2 > len1)
@@ -193,6 +198,7 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2)
inlen -= len1 - len2;
haystack = (char *)realloc(haystack, inlen * sizeof(char *));
+ found = haystack + index;
if (len2 > len1)
memmove(found + len2, found + len1, inlen - len1 - (found - haystack));