Fix compiler warnings

This commit is contained in:
Maschell 2020-08-23 13:06:39 +02:00
parent 09d6b9f756
commit a9ab6078c8

View File

@ -270,20 +270,22 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
if (len_rep == 0) { if (len_rep == 0) {
return NULL; return NULL;
} // empty rep causes infinite loop during count } // empty rep causes infinite loop during count
if (!with) if (!with) {
with = ""; with = (char *) "";
}
len_with = strlen(with); len_with = strlen(with);
// count the number of replacements needed // count the number of replacements needed
ins = orig; ins = orig;
for (count = 0; tmp = strstr(ins, rep); ++count) { for (count = 0; (tmp = strstr(ins, rep)); ++count) {
ins = tmp + len_rep; ins = tmp + len_rep;
} }
tmp = result = (char *) malloc(strlen(orig) + (len_with - len_rep) * count + 1); tmp = result = (char *) malloc(strlen(orig) + (len_with - len_rep) * count + 1);
if (!result) if (!result) {
return NULL; return NULL;
}
// first time through the loop, all the variable are set correctly // first time through the loop, all the variable are set correctly
// from here on, // from here on,