From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id c47e639f for ; Tue, 17 Dec 2019 07:45:12 +0000 (UTC) Received: (qmail 9851 invoked by alias); 17 Dec 2019 07:45:07 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45064 Received: (qmail 4647 invoked by uid 1010); 17 Dec 2019 07:45:07 -0000 X-Qmail-Scanner-Diagnostics: from wout4-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25663. spamassassin: 3.4.2. Clear:RC:0(64.147.123.20):SA:0(-1.9/5.0):. Processed in 1.69371 secs); 17 Dec 2019 07:45:07 -0000 X-Envelope-From: danielsh@apache.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: softfail (ns1.primenet.com.au: transitioning SPF record at amazonses.com does not designate 64.147.123.20 as permitted sender) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvddtiedguddufecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffosedttdertdertd dtnecuhfhrohhmpeffrghnihgvlhcuufhhrghhrghfuceouggrnhhivghlshhhsegrphgr tghhvgdrohhrgheqnecukfhppeejledrudektddrheejrdduudelnecurfgrrhgrmhepmh grihhlfhhrohhmpegurghnihgvlhhshhesrghprggthhgvrdhorhhgnecuvehluhhsthgv rhfuihiivgeptd X-ME-Proxy: From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH 1/3] Fix the mktemp() warning, in debug builds only. Date: Tue, 17 Dec 2019 07:44:26 +0000 Message-Id: <20191217074428.3699-1-danielsh@apache.org> X-Mailer: git-send-email 2.11.0 On Linux, linking to mktemp() generates the following warning: . utils.o: In function `gettempname': ./Src/utils.c:2229: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp' The warning cannot be disabled. Work around that by using mkstemp() instead, and massage its output so it behaves like mktemp(). See the new comment for further details. --- The purpose of this patch is to eliminate the spurious warning from the edit-compile-test cycle. Cheers, Daniel Src/utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Src/utils.c b/Src/utils.c index 1d916e71f..086c0dfcb 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -2201,6 +2201,31 @@ gettempname(const char *prefix, int use_heap) #ifdef HAVE__MKTEMP /* Zsh uses mktemp() safely, so silence the warnings */ ret = (char *) _mktemp(ret); +#elif HAVE_MKSTEMP && defined(DEBUG) + { + /* zsh uses mktemp() safely (all callers use O_EXCL, and one of them + * uses mkfifo()/mknod(), as opposed to open()), but some compilers + * warn about this anyway and give no way to disable the warning. To + * appease them, use mkstemp() and then close the fd and unlink the + * filename, to match callers' expectations. + * + * But do this in debug builds only, because we don't want to suffer + * x3 the disk access (touch, unlink, touch again) in production. + */ + int fd; + errno = 0; + fd = mkstemp(ret); + if (fd < 0) + zwarn("can't get a temporary filename: %e", errno); + else { + close(fd); + ret = ztrdup(ret); + + errno = 0; + if (unlink(ret) < 0) + zwarn("unlinking a temporary filename failed: %e", errno); + } + } #else ret = (char *) mktemp(ret); #endif