From owner-svn-src-all@freebsd.org Sat Jan 26 23:28:25 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 9807814B29F3; Sat, 26 Jan 2019 23:28:25 +0000 (UTC) (envelope-from devin@shxd.cx) Received: from shxd.cx (mail.shxd.cx [64.201.244.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 0068D72476; Sat, 26 Jan 2019 23:28:25 +0000 (UTC) (envelope-from devin@shxd.cx) Received: from [76.77.180.168] (port=52601 helo=[192.168.86.32]) by shxd.cx with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.77 (FreeBSD)) (envelope-from ) id 1gnWcE-000GoJ-Jl; Sat, 26 Jan 2019 14:39:54 -0800 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: svn commit: r343480 - head/lib/libfigpar From: Devin Teske X-Mailer: iPhone Mail (15D60) In-Reply-To: <010001688c2cfc3e-e319d851-8b9e-4468-8bd1-f93331f35116-000000@email.amazonses.com> Date: Sat, 26 Jan 2019 15:28:22 -0800 Cc: rgrimes@freebsd.org, Stefan Esser , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <75F63D9C-0EF2-40EB-BDC6-A2ADFD3C3A89@freebsd.org> References: <201901262136.x0QLaAJv095518@pdx.rh.CN85.dnsmgr.net> <010001688c2cfc3e-e319d851-8b9e-4468-8bd1-f93331f35116-000000@email.amazonses.com> To: Colin Percival Sender: devin@shxd.cx X-Rspamd-Queue-Id: 0068D72476 X-Spamd-Bar: ++++ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [4.62 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; IP_SCORE(0.21)[ip: (0.59), ipnet: 64.201.240.0/20(0.30), asn: 36734(0.24), country: US(-0.08)]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[freebsd.org]; AUTH_NA(1.00)[]; NEURAL_SPAM_MEDIUM(0.93)[0.928,0]; RCPT_COUNT_FIVE(0.00)[6]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_SPAM_SHORT(0.83)[0.826,0]; MX_GOOD(-0.01)[cached: mail.shxd.cx]; NEURAL_SPAM_LONG(0.97)[0.970,0]; R_SPF_NA(0.00)[]; FORGED_SENDER(0.30)[dteske@freebsd.org,devin@shxd.cx]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:36734, ipnet:64.201.240.0/20, country:US]; FROM_NEQ_ENVFROM(0.00)[dteske@freebsd.org,devin@shxd.cx]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2] 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 23:28:25 -0000 > On 26 Jan 2019, at 1:59 PM, Colin Percival wrote: >=20 > On 1/26/19 1:36 PM, Rodney W. Grimes wrote: >>> Author: se >>> Date: Sat Jan 26 21:30:26 2019 >>> New Revision: 343480 >>> URL: https://svnweb.freebsd.org/changeset/base/343480 >>>=20 >>> Log: >>> Silence Clang Scan warning about potentially unsafe use of strcpy. >>>=20 >>> While this is a false positive, the use of strdup() simplifies the code= . >>=20 >> Though that might be true, it also has to recalculate the >> length of the string which was already known by slen. >>=20 >> I am not sure how often this code is called, >> but that is wasted cycles in a library. >=20 > The length of the string was already being recalculated, by strcpy. >=20 > It seems to me that this could be written as >=20 > temp =3D malloc(slen + 1); > if (temp =3D=3D NULL) /* could not allocate memory */ > return (-1); > memcpy(temp, source, slen + 1); >=20 > which avoids both recalculating the string length and using strcpy? >=20 Thanks for fixing that. =E2=80=94=20 Cheers, Devin >>> Modified: head/lib/libfigpar/string_m.c >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D >>> --- head/lib/libfigpar/string_m.c Sat Jan 26 20:43:28 2019 (r34347= 9) >>> +++ head/lib/libfigpar/string_m.c Sat Jan 26 21:30:26 2019 (r34348= 0) >>> @@ -119,10 +119,9 @@ replaceall(char *source, const char *find, const ch= ar=20 >>>=20 >>> /* If replace is longer than find, we'll need to create a temp copy *= / >>> if (rlen > flen) { >>> - temp =3D malloc(slen + 1); >>> - if (errno !=3D 0) /* could not allocate memory */ >>> + temp =3D strdup(source); >>> + if (temp =3D=3D NULL) /* could not allocate memory */ >>> return (-1); >>> - strcpy(temp, source); >>> } else >>> temp =3D source;