zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: segmentation fault with {1..1234567}
Date: Sun, 6 Jul 2014 19:30:55 +0100	[thread overview]
Message-ID: <20140706193055.209f7a2b@pws-pc.ntlworld.com> (raw)
In-Reply-To: <140706091609.ZM18865@torch.brasslantern.com>

On Sun, 06 Jul 2014 09:16:09 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> In any case I'm not in a position to continue debating this.  Zsh treats
> out of memory as a fatal error at nearly the lowest levels of its memory
> management and that's not changing without some major rewriting.

This is generally true, but it's not quite the problem in this case.  Here
we don't actually need to be out of memory if we allocate it appropriately.

> } NEVER use alloca to allocate a lot of memory. That's a well-known bug!
> 
> IIRC the use of VARARR() was introduced in order to more evenly split the
> memory use between the heap and the stack on systems that had limited RAM.
> Obviously more recent hardware is likely to have divided process address
> space differently, and this former optimization has become a liability.

Well, all I can say is that without the following change it crashes on
my system (where I have not tweaked any limits) and with the following
change it doesn't.

Maybe I'm just selfish but I prefer the latter.

diff --git a/Src/builtin.c b/Src/builtin.c
index 42354b9..3af5fb9 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -280,8 +280,8 @@ execbuiltin(LinkList args, Builtin bn)
 	 * after option processing, but it makes XTRACE output
 	 * much simpler.
 	 */
-	VARARR(char *, argarr, argc + 1);
 	char **argv;
+	char **argarr = zhalloc((argc + 1)*sizeof(char *));
 
 	/*
 	 * Get the actual arguments, into argv.  Remember argarr


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2014-07-06 18:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-04 17:25 Vincent Lefevre
2014-07-05  1:40 ` Bart Schaefer
2014-07-05 11:12   ` Vincent Lefevre
2014-07-05 16:57     ` Bart Schaefer
2014-07-05 23:39       ` Vincent Lefevre
2014-07-06  0:09         ` Vincent Lefevre
2014-07-06 19:46           ` Bart Schaefer
2014-07-07  1:12             ` Vincent Lefevre
2014-07-06 16:16         ` Bart Schaefer
2014-07-06 18:30           ` Peter Stephenson [this message]
2014-07-06 19:46             ` Bart Schaefer
2014-07-06 22:23               ` Mikael Magnusson
2014-07-07 19:33               ` Peter Stephenson
2014-07-08  1:08                 ` Bart Schaefer
2014-07-08 10:38                   ` Peter Stephenson
2014-07-24  9:44                     ` Peter Stephenson
2014-07-24 15:35                       ` 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=20140706193055.209f7a2b@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).