From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22804 invoked by alias); 13 Jul 2010 08:48:53 -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: X-Seq: 28072 Received: (qmail 3677 invoked from network); 13 Jul 2010 08:48:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Tue, 13 Jul 2010 09:48:16 +0100 From: Peter Stephenson To: Ben Hoskings , zsh-workers@zsh.org Subject: Re: Bug report: segfault when function and alias names collide Message-ID: <20100713094816.1fd35b91@csr.com> In-Reply-To: References: Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.18.9; i686-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 13 Jul 2010 08:48:16.0734 (UTC) FILETIME=[22E187E0:01CB2268] X-Scanned-By: MailControl A_09_40_00 (www.mailcontrol.com) on 10.68.1.123 On Tue, 13 Jul 2010 10:34:11 +1000 Ben Hoskings wrote: > Just accidentally defined a function with the same name as an alias, > which caused a segfault. (I was replacing the alias with a function, > and loading the new function with '. ~/.zshrc', which caused both to > be defined at once.) > > alias gls='glog -S' > gls() { > query="$1" > shift > glog --pickaxe-regex "-S$query" "$@" > } > > This command segfaulted zsh: > > $ gls content_for Yes, you've created an infinite recursion. The shell has a limit on its recursion depth so on some systems you would get glog:3: maximum nested function level reached which would tell you something is screwy without crashing. However, the limit is a bit hit and miss. If we reduce it we get reports that it's too low, etc. To avoid it, you can either define the alias after the function, or to be safer if you know you're defining both you can quote the name of the function, or simply use the other form of function definition: alias gls='glog -S' function gls { query="$1" shift glog --pickaxe-regex "-S$query" "$@" } That still defines gls as a function but the "gls" at this point isn't expanded as an alias. (I don't know of any good reason why it's necessary to expand aliases at that point, beyond the fact that that's how the parser works---words in command position are always expanded and making exceptions is tricky.) -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom