zsh-workers
 help / color / mirror / code / Atom feed
From: Gilles <gilles.usenet@gmail.com>
To: zsh-workers@zsh.org
Subject: [BUG] crash when I unset and redefine a function within itself
Date: Wed, 16 Oct 2024 19:55:57 +0200	[thread overview]
Message-ID: <CAHf9+CvfRwuwAEFLgOqEpjM6bAZtg4r2BgRgr1rZNf-akmJgyg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 747 bytes --]

With zsh 5.9 from Ubuntu 24.04 x86_64, or with the latest version from git
(383526da422cf1c962d9be7e9e6ac166e226bf2b) compiled locally, the shell
segfaults when I run a function that undefines then redefines itself.

zsh -c 'foo () { unset -f foo; foo () { echo redefined; }; }; foo'
[1]    89793 segmentation fault (core dumped)  zsh -c 'foo () { unset -f
foo; foo () { echo redefined; }; }; foo'

This works with zsh 5.8.1 on Ubuntu 22.04 and older versions.

Workaround: if you redefine a function within itself, make sure not to
unset it first.

This is simplified from real code in my .zshrc that decides on first use
whether the command name foo should invoke the external command directly or
be a function that wraps around it.

-- 
Gilles

[-- Attachment #2: Type: text/html, Size: 938 bytes --]

             reply	other threads:[~2024-10-16 17:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16 17:55 Gilles [this message]
2024-10-16 19:54 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHf9+CvfRwuwAEFLgOqEpjM6bAZtg4r2BgRgr1rZNf-akmJgyg@mail.gmail.com \
    --to=gilles.usenet@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).