Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Jan 2019 22:24:15 +0000 (UTC)
From:      Stefan Esser <se@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r343482 - head/lib/libfigpar
Message-ID:  <201901262224.x0QMOFca034234@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201901262224.x0QMOFca034234>