From owner-svn-src-all@freebsd.org Sat Jan 26 21:36:20 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A88FA14AF224; Sat, 26 Jan 2019 21:36:20 +0000 (UTC) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (br1.CN84in.dnsmgr.net [69.59.192.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B67BE6E69E; Sat, 26 Jan 2019 21:36:19 +0000 (UTC) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (localhost [127.0.0.1]) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3) with ESMTP id x0QLaAhr095519; Sat, 26 Jan 2019 13:36:10 -0800 (PST) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: (from freebsd@localhost) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3/Submit) id x0QLaAJv095518; Sat, 26 Jan 2019 13:36:10 -0800 (PST) (envelope-from freebsd) From: "Rodney W. Grimes" Message-Id: <201901262136.x0QLaAJv095518@pdx.rh.CN85.dnsmgr.net> Subject: Re: svn commit: r343480 - head/lib/libfigpar In-Reply-To: <201901262130.x0QLUQnf002874@repo.freebsd.org> To: Stefan Esser Date: Sat, 26 Jan 2019 13:36:10 -0800 (PST) CC: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Reply-To: rgrimes@freebsd.org X-Mailer: ELM [version 2.4ME+ PL121h (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: B67BE6E69E X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.97 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.973,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Jan 2019 21:36:20 -0000 > Author: se > Date: Sat Jan 26 21:30:26 2019 > New Revision: 343480 > URL: https://svnweb.freebsd.org/changeset/base/343480 > > Log: > Silence Clang Scan warning about potentially unsafe use of strcpy. > > While this is a false positive, the use of strdup() simplifies the code. Though that might be true, it also has to recalculate the length of the string which was already known by slen. I am not sure how often this code is called, but that is wasted cycles in a library. > > 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 20:43:28 2019 (r343479) > +++ head/lib/libfigpar/string_m.c Sat Jan 26 21:30:26 2019 (r343480) > @@ -119,10 +119,9 @@ 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 = malloc(slen + 1); > - if (errno != 0) /* could not allocate memory */ > + temp = strdup(source); > + if (temp == NULL) /* could not allocate memory */ > return (-1); > - strcpy(temp, source); > } else > temp = source; > > > -- Rod Grimes rgrimes@freebsd.org