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:
Stefan Eßer 2019-01-26 22:24:15 +00:00
parent 3db348b54a
commit 59ba78ccae
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=343482

View file

@ -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;