Browse Source

* Fix a bug in replace().

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/cacamoo/trunk@1265 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 18 years ago
parent
commit
a308b80e12
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      src/main.c

+ 2
- 2
src/main.c View File

@@ -458,7 +458,7 @@ char *replace(char *s1, char *oldpiece, const char *newpiece)
tocopy = strlen(s1 + i1); tocopy = strlen(s1 + i1);
if(oldlen < newlen) if(oldlen < newlen)
s2 = realloc(s2, i2 + tocopy + 1); s2 = realloc(s2, i2 + tocopy + 1);
memmove(s2 + i2, s1 + i1, tocopy + 1);
memcpy(s2 + i2, s1 + i1, tocopy + 1);
if(oldlen < newlen) if(oldlen < newlen)
free(s1); free(s1);
return s2; return s2;
@@ -468,7 +468,7 @@ char *replace(char *s1, char *oldpiece, const char *newpiece)
if(oldlen < newlen) if(oldlen < newlen)
s2 = realloc(s2, i2 + tocopy + newlen); s2 = realloc(s2, i2 + tocopy + newlen);
memmove(s2 + i2, s1 + i1, tocopy); memmove(s2 + i2, s1 + i1, tocopy);
memcpy(s2 + tocopy, newpiece, newlen);
memcpy(s2 + i2 + tocopy, newpiece, newlen);
i1 += tocopy + oldlen; i1 += tocopy + oldlen;
i2 += tocopy + newlen; i2 += tocopy + newlen;
} }


Loading…
Cancel
Save