zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: Ben Hoskings <ben@hoskings.net>, zsh-workers@zsh.org
Subject: Re: Bug report: segfault when function and alias names collide
Date: Tue, 13 Jul 2010 09:48:16 +0100	[thread overview]
Message-ID: <20100713094816.1fd35b91@csr.com> (raw)
In-Reply-To: <AANLkTikqhsKJ0UhN2D0OaA45c0-pY-GgTRotQcbbsD5w@mail.gmail.com>

On Tue, 13 Jul 2010 10:34:11 +1000
Ben Hoskings <ben@hoskings.net> 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 <pws@csr.com>            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


      reply	other threads:[~2010-07-13  8:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-13  0:34 Ben Hoskings
2010-07-13  8:48 ` Peter Stephenson [this message]

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=20100713094816.1fd35b91@csr.com \
    --to=peter.stephenson@csr.com \
    --cc=ben@hoskings.net \
    --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).