zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] crash when I unset and redefine a function within itself
@ 2024-10-16 17:55 Gilles
  2024-10-16 19:54 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Gilles @ 2024-10-16 17:55 UTC (permalink / raw)
  To: zsh-workers

[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-16 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-16 17:55 [BUG] crash when I unset and redefine a function within itself Gilles
2024-10-16 19:54 ` Bart Schaefer

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).