Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: segmentation fault with {1..1234567}



On 2014-07-04 18:40:36 -0700, Bart Schaefer wrote:
> On Jul 4,  7:25pm, Vincent Lefevre wrote:
> }
> } With zsh 5.0.5 (Debian/unstable):
> } 
> } $ zsh -c 'echo {1..1234567}'
> } zsh: segmentation fault (core dumped)  zsh -c 'echo {1..1234567}'
> } 
> } If a failure is expected for any reason, it shouldn't be a crash.
> 
> Whether that expression fails depends entirely on the memory allocation
> limitations of the local host.  It works fine for me.

That's not a memory allocation problem: it fails on a machine
with 24GB!

> What's the "expected" behavior of the shell when the user requests a
> vast amount of memory?  How should the shell recover from running out of
> memory at any arbitrary point during execution of a command or script?
> Is it really helpful to trap the signal and exit *without* dumping core?

No, the signal means that it is already too late. You should really
check the return code of malloc and so on. If this comes from a
command like here, the best thing is to make it fail, e.g. in an
interactive shell:

$ some_command
zsh: out of memory
$

with $? being non-zero, and possibly with some details in the message.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author