From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10132 invoked by alias); 12 Jul 2015 17:24:47 -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: 35780 Received: (qmail 23190 invoked from network); 12 Jul 2015 17:24:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) 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, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=dtgmcAU4 c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=NLZqzBF-AAAA:8 a=IkcTkHD0fZMA:10 a=muCTmQ-6rbQ5LtiXjGgA:9 a=0lttxSZ90MG6wuwU:21 a=cs3NK81iwXOhqcJb:21 a=QEXdDO2ut3YA:10 Date: Sun, 12 Jul 2015 18:19:06 +0100 From: Peter Stephenson To: "zsh-workers@zsh.org" Subject: Re: Parser bugs: "local a=()" Message-ID: <20150712181906.4dd619a7@ntlworld.com> In-Reply-To: <766191.98675.qm@web100002.mail.kks.yahoo.co.jp> References: <766191.98675.qm@web100002.mail.kks.yahoo.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, 12 Jul 2015 18:13:18 +0900 (JST) ryosuke_i_628@yahoo.co.jp wrote: > func4() { > local a=3D() > local b=3Dfalse > echo "a in func4 length: ${#a[@]}" > } > example@local:~$ func4 > a in func4 length: 0 > [1] 135208 segmentation fault =C2=A0zsh =20 Parsing of this has changed recently (since 5.0.8), but you can see what the effect is by doing (whatever the version) func4() { \local a=3D() \local b=3Dfalse echo "a in func4 length: ${#a[@]}" } (this suppresses the new special parsing of "local"). Running this gives me: :3: maximum nested function level reached with no segmentation violation, but I would guess the recursive call is the key to the problem --- there's no robust way for the shell to find out it's used as many resources and it can and unwind safely, so the builtin limit is just a guess whose effect is highly system dependent and that tends to get worse as time goes on and specs change. You can see why by doing: functions local local () { \local b=3Dfalse } What's happened is the multiple function definition code has defined functions called "local" and "a=3D" with the body on the next line (as there are no braces, it's a single line definition). "\local b=3Dfalse". So invoking local causes infinite recursion. At the time, this was actually correct parsing according to the rules in force, if extremely obscure. Things you can do to protect yourself (apart from upgrading to the next release, currently vapourware) include "unsetopt multifuncdef" to disallow the also rather obscure and not often used feature of defining multiple functions in one go. When something like this has come up before. we've never managed to work out a safer way of handling recursive functions that's both robust and non-intrusive, i.e. doesn't forbid useful behaviour. pws