From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28803 invoked from network); 2 Jan 2021 16:42:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Jan 2021 16:42:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1609605722; b=V0MXVzbs4I4TbY8H4w/NLNEbqSWPD+wLCwt+ozclleC2l7necjUIokCWm54FUzUVHnrNofhEtI zyntQb9Kl3SPtEwbzsRmDFQG3tmTXwxeZDyG4HreXrDOL0hi3W6Tauj8zzM6nUWLAcEGGmjm6D /3C+0EQgxgMaLouLZb0jhx95Nu/qSSpr3JfgP6gMlsXvZKXJKTiM4WZC5vbyZKLDxo3rRwa6mw j3yMNOrREK0QIP/6zBM9X5fn4k86R+iljBQrmTVa/9sjRp35l9C273BibohvgDT4oggq5pUkip NsCooJQ4q0beboTnaClA+iM+c0Ojf374EW9NCNFP5j4bXA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-io1-f41.google.com) smtp.remote-ip=209.85.166.41; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1609605722; bh=oy+cOxn/++WSGlrD1W3RUb+4lEDyVnW2Kafuy6cubaU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:References:In-Reply-To:MIME-Version:DKIM-Signature: DKIM-Signature; b=MMx3R6AqSVnUbx+6+Z00GgvXo5LsLlxdNYvD4G+VxRyCKplMIeN+W5MDp1waOTNnXBh1BJTNrG MX6J7yMu3lDBIzuUB+g2kbrTNNWPyaj/VFn8BC/5Zm69kIlNlVKFJpaRj7dEibMEvo72o0P9Jb D5JQODigIvcjcGx9/xPX4n+exjVgzQU0Qt8i+Y+H9ORGtFUJBIrRZCKJ5PCOMyIKC8VqYTnpGe MAhi8o/1kIbit45WtzOCVRopZIfI1IRdx2O5BkcHp4xy55K+8PPqLFlgD3Qavno6A22cXjlomb exwYk5+3RDp4MhmZVVM+zQomEF7VyvFPOUXSJxYMkFcHKw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:References:In-Reply-To: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=kfLqntEmkXxlceLKetDUrU+AFV9ipObJK6ojSVJN0IY=; b=K0bXNVmdzbjKgvd8mbFilVRXnR 2QhtUznxsTkVoKWL5bQqY1exoBiNl12jcy8koXcSNhA2dRkYChUf8sivSVcMGPrKYO8GfyK1nQwRk RNk9W1Ox4aMdjN7pHS+RNa/5UhE/ro7KZVItY7fihe+/diQKkofAvVqCTYVpHZFvMHeltO0MY+OGN pkl5gT7wPlS8ZPh3RxEPDYQLG9eAVPFIHpRGssA5iFrLyRpiAdHInrEeU3i2JwQ/dPnVBsBEBLpWN PYRpyiOKLMt7Oxhf1fIPTGXeM1dzHNgLIg51sfcCKwWhGXIQqmAy3DLzQUD02Tr+QT46/fytjlKTd 3rZl7gGA==; Received: from authenticated user by zero.zsh.org with local id 1kvjyb-000B1y-Vj; Sat, 02 Jan 2021 16:42:02 +0000 Authentication-Results: zsh.org; iprev=pass (mail-io1-f41.google.com) smtp.remote-ip=209.85.166.41; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-io1-f41.google.com ([209.85.166.41]:37501) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kvjyH-000AsW-Ko; Sat, 02 Jan 2021 16:41:42 +0000 Received: by mail-io1-f41.google.com with SMTP id p187so21123471iod.4 for ; Sat, 02 Jan 2021 08:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=kfLqntEmkXxlceLKetDUrU+AFV9ipObJK6ojSVJN0IY=; b=XW4AKxiZ1mLPC7O5d+/F3FQTDnYcFShKZkA6Fgw9dsEi/xmuC/4clT+WA88sQVAkLS 5OG8kTHjUM1JyeQGhDvgCSpB8QVg2K/YFhy/BoW+mvCtRHw2R7Okb8mcfjUZfzPjFXdS Pnlhgyq9JmOyzS7Ru7VmxqtulT6mu4OKHeLJywBIcd1sQR6qy5w62km9KRTjiYW+gM4a W3LTFzlxWI5ayYkAHELbJ6R5hRoypQWMyRpZk3LHaBA3nwZmZayjs9s1ycg0B3J7Lngi fZaPpw6OFI0eMtuNq8BEwh/A0AeUiP/QMOg7gSsrfx59gUXbgqSVBT7G8XCUYYGazCAF B+GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=kfLqntEmkXxlceLKetDUrU+AFV9ipObJK6ojSVJN0IY=; b=NCDHLHMc/vpnQE1eaqxQsIzpReaKeu3rI6j/7W35uta0yjf5ke39EkWVffUKFHw4tC n+kixvpdphAtMtIdGl0VhXIpekqrqOtk2ZxnLvFgZ61SbhUocUJiASYGn8dMuJDypFN6 BcMgasp0U/vgO2jY99igP78J25TbMslH7Hq2rw+AlBy+aVm+26XM0qRKTDvfiAneeiFx YpxCBZO/8jZ2DAh/Sx6SiZA5fOPdIlNAEUNSj0fRNdmlDDB0yhUwrpZKC55lFlg+/Ph6 Rnl6Kl/K/NOHTJLQPfu1x/xoHtHgelGxhYRRBfxZr2f+2mFIZGgylDbfWxXfGnXasfyU PP9A== X-Gm-Message-State: AOAM532LgQV8q0+f7Xxc2e2eslx2BKB1L9ouPhEhDdDNKDZsEQeY1GSe AfPxP16fLD5hIXzewKDq+J4yhEXywLFEmSa8/OA= X-Google-Smtp-Source: ABdhPJxtsH2PjyvjP74XB9JTDSMGs0kqthgfccMYdSZIQRhqUD1rpk75gHPTAX/X5keqnb26HWubIoo3vVOMWlPbuOo= X-Received: by 2002:a05:6602:2dcf:: with SMTP id l15mr52221563iow.120.1609605699934; Sat, 02 Jan 2021 08:41:39 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a4f:ac4a:0:0:0:0:0 with HTTP; Sat, 2 Jan 2021 08:41:39 -0800 (PST) In-Reply-To: <8591b9d9-f2f0-4045-b8e2-d1b759a360c0@www.fastmail.com> References: <20201231054131.682544-1-felipe.contreras@gmail.com> <20201231054131.682544-2-felipe.contreras@gmail.com> <8591b9d9-f2f0-4045-b8e2-d1b759a360c0@www.fastmail.com> From: Mikael Magnusson Date: Sat, 2 Jan 2021 17:41:39 +0100 Message-ID: Subject: Re: [PATCH 1/3] src: fix build warnings To: Daniel Shahaf Cc: Felipe Contreras , zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 47788 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On 1/2/21, Daniel Shahaf wrote: > Felipe Contreras wrote on Thu, 31 Dec 2020 05:41 +00:00: >> utils.c: In function =E2=80=98getkeystring=E2=80=99: >> cc1: warning: function may return address of local variable >> [-Wreturn-local-addr] >> utils.c:6703:16: note: declared here >> 6703 | char *buf, tmp[1]; >> | ^~~ >> >> diff --git a/Src/utils.c b/Src/utils.c >> index 5151b89a8..37ae4c854 100644 >> --- a/Src/utils.c >> +++ b/Src/utils.c >> @@ -6700,7 +6700,8 @@ ucs4toutf8(char *dest, unsigned int wval) >> mod_export char * >> getkeystring(char *s, int *len, int how, int *misc) >> { >> - char *buf, tmp[1]; >> + static char tmp[1]; >> + char *buf; > > The docstring explicitly promises the returned string will be newly- > allocated from the heap, so this change makes the implementation > inconsistent with the docstring. If we ever return the address of tmp, bad things are likely to happen regardless of the static so hopefully that never happens. Returning the address of a local variable basically means it will be junk (current hypothetical behavior), whereas returning a static means the function wouldn't be re-entrant (hypothetical behavior with the patch). I don't think any reading of "newly allocated from the heap" would include a location on a popped stack though, so I don't see how the docstring enters into it at all. --=20 Mikael Magnusson