(string_replace_substring) Add early return if 'in' is NULL

This commit is contained in:
twinaphex 2015-03-13 15:55:12 +01:00
parent e4cfbcf93a
commit a6fc76ac87

View File

@ -24,14 +24,18 @@
char *string_replace_substring(const char *in, const char *pattern, const char *by) char *string_replace_substring(const char *in, const char *pattern, const char *by)
{ {
char *needle; char *needle = NULL, *res = NULL;
size_t outsize = strlen(in) + 1; size_t outsize = 0;
/* use this to iterate over the output */
size_t resoffset = 0; size_t resoffset = 0;
if (!in)
return NULL;
outsize = strlen(in) + 1;
/* TODO maybe avoid reallocating by counting the /* TODO maybe avoid reallocating by counting the
* non-overlapping occurences of pattern */ * non-overlapping occurences of pattern */
char *res = malloc(outsize); res = (char*)malloc(outsize);
if (!res) if (!res)
return NULL; return NULL;