svn commit: r343482 - head/lib/libfigpar

Stefan Esser se at FreeBSD.org
Sat Jan 26 22:24:16 UTC 2019


Author: se
Date: Sat Jan 26 22:24:15 2019
New Revision: 343482
URL: https://svnweb.freebsd.org/changeset/base/343482

Log:
  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

Modified:
  head/lib/libfigpar/string_m.c

Modified: head/lib/libfigpar/string_m.c
==============================================================================
--- head/lib/libfigpar/string_m.c	Sat Jan 26 21:35:51 2019	(r343481)
+++ head/lib/libfigpar/string_m.c	Sat Jan 26 22:24:15 2019	(r343482)
@@ -119,9 +119,10 @@ replaceall(char *source, const char *find, const char 
 
 	/* 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;
 


More information about the svn-src-head mailing list