diff options
author | Stefan Eßer <se@FreeBSD.org> | 2019-01-26 22:24:15 +0000 |
---|---|---|
committer | Stefan Eßer <se@FreeBSD.org> | 2019-01-26 22:24:15 +0000 |
commit | 59ba78ccae74a8a116e4784b4edb840dae61610d (patch) | |
tree | f5e4aac0aafc14fa9406f58ef039d96992e7cdd2 /lib/libfigpar | |
parent | 3db348b54a93de22271e7c83f11e24abe228f6ba (diff) | |
download | src-test-59ba78ccae74a8a116e4784b4edb840dae61610d.tar.gz src-test-59ba78ccae74a8a116e4784b4edb840dae61610d.zip |
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
Notes
Notes:
svn path=/head/; revision=343482
Diffstat (limited to 'lib/libfigpar')
-rw-r--r-- | lib/libfigpar/string_m.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/libfigpar/string_m.c b/lib/libfigpar/string_m.c index c991aebb4a575..158774143ec3d 100644 --- a/lib/libfigpar/string_m.c +++ b/lib/libfigpar/string_m.c @@ -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; |