Added more tests to str_replace

Handles NULLs and empty strings better
This commit is contained in:
James Booth
2012-04-19 22:57:22 +01:00
parent 366eecc195
commit 4f454b6a64
2 changed files with 102 additions and 1 deletions

7
util.c
View File

@@ -62,7 +62,12 @@ char * str_replace (const char *string, const char *substr,
char *oldstr = NULL;
char *head = NULL;
if ( substr == NULL || replacement == NULL )
if (string == NULL)
return NULL;
if ( substr == NULL ||
replacement == NULL ||
(strcmp(substr, "") == 0))
return strdup (string);
newstr = strdup (string);