From owner-dev-commits-src-all@freebsd.org Mon Feb 1 12:40:40 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7E3514FEA41; Mon, 1 Feb 2021 12:40:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DTnbq6pKDz3DtD; Mon, 1 Feb 2021 12:40:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EB3641B629; Mon, 1 Feb 2021 12:40:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 111CecXu094762; Mon, 1 Feb 2021 12:40:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 111CecuM094761; Mon, 1 Feb 2021 12:40:38 GMT (envelope-from git) Date: Mon, 1 Feb 2021 12:40:38 GMT Message-Id: <202102011240.111CecuM094761@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 3eae6412b50b - stable/13 - libc: try to skip memcpy in _gettemp MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3eae6412b50bbcfe1a7affc26202dc896aedd1ab Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Feb 2021 12:40:40 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=3eae6412b50bbcfe1a7affc26202dc896aedd1ab commit 3eae6412b50bbcfe1a7affc26202dc896aedd1ab Author: Mateusz Guzik AuthorDate: 2021-01-24 04:34:22 +0000 Commit: Mateusz Guzik CommitDate: 2021-02-01 12:39:15 +0000 libc: try to skip memcpy in _gettemp (cherry picked from commit b22fdf45ff8ef1d1f9a6c28f1d7f59ca4b012da6) --- lib/libc/stdio/mktemp.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c index c47e0221e5cd..0ede3058a3d5 100644 --- a/lib/libc/stdio/mktemp.c +++ b/lib/libc/stdio/mktemp.c @@ -123,6 +123,7 @@ _gettemp(int dfd, char *path, int *doopen, int domkdir, int slen, int oflags) struct stat sbuf; uint32_t rand; char carrybuf[MAXPATHLEN]; + int saved; if ((doopen != NULL && domkdir) || slen < 0 || (oflags & ~(O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC | @@ -151,9 +152,7 @@ _gettemp(int dfd, char *path, int *doopen, int domkdir, int slen, int oflags) } start = trv + 1; - /* save first combination of random characters */ - memcpy(carrybuf, start, suffp - start); - + saved = 0; oflags |= O_CREAT | O_EXCL | O_RDWR; for (;;) { if (doopen) { @@ -170,6 +169,12 @@ _gettemp(int dfd, char *path, int *doopen, int domkdir, int slen, int oflags) } else if (lstat(path, &sbuf)) return (errno == ENOENT); + /* save first combination of random characters */ + if (!saved) { + memcpy(carrybuf, start, suffp - start); + saved = 1; + } + /* If we have a collision, cycle through the space of filenames */ for (trv = start, carryp = carrybuf;;) { /* have we tried all possible permutations? */