Slightly improve previous commit that silenced a Clang Scan warning.
The strdup() call does not take advantage of the known length of the source string. Replace by malloc() and memcpy() utilizimng the pre- calculated string length. Submitted by: cperciva Reported by: rgrimes MFC after: 2 weeks
This commit is contained in:
parent
4045e6e64f
commit
72986d9f4b
@ -119,9 +119,10 @@ replaceall(char *source, const char *find, const char *replace)
|
||||
|
||||
/* If replace is longer than find, we'll need to create a temp copy */
|
||||
if (rlen > flen) {
|
||||
temp = strdup(source);
|
||||
temp = malloc(slen + 1);
|
||||
if (temp == NULL) /* could not allocate memory */
|
||||
return (-1);
|
||||
memcpy(temp, source, slen + 1);
|
||||
} else
|
||||
temp = source;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user