Prevent potencial bug: use memmove() instead strcpy() for overlap source and destination

This commit is contained in:
Stas Degteff 2011-02-21 13:08:04 +00:00
parent bf13c6929a
commit f7f092da62

View File

@ -156,7 +156,8 @@ static char* strdel(const char* substr, char* str) {
if(!dest) if(!dest)
return NULL; return NULL;
char* src = dest + strlen(substr); char* src = dest + strlen(substr);
strcpy(dest, src); /* Source and destination overlap. This is rigth. */ // strcpy(dest, src); /* Source and destination overlap. This is rigth. */
memmove(dest, src, strlen(src)+1);
return str; return str;
} }
@ -171,7 +172,8 @@ static char* stridel(const char* substr, char* str) {
if(!dest) if(!dest)
return NULL; return NULL;
char* src = dest + strlen(substr); char* src = dest + strlen(substr);
strcpy(dest, src); // strcpy(dest, src);
memmove(dest, src, strlen(src)+1); /* Source and destination overlaps. */
return str; return str;
} }