From 72986d9f4bc1aec9938dbd6e743ded3cd584d508 Mon Sep 17 00:00:00 2001 From: se Date: Sat, 26 Jan 2019 22:24:15 +0000 Subject: [PATCH] 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 --- lib/libfigpar/string_m.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libfigpar/string_m.c b/lib/libfigpar/string_m.c index c991aebb4a57..158774143ec3 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;