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

Re: unbounded recursive call in a shell script crashes zsh



Bart Schaefer wrote on Sun, Apr 16, 2017 at 14:00:16 -0700:
> On Apr 16,  6:56pm, Daniel Shahaf wrote:
> }
> } Hmm.  Would it work to measure the stack space used, by declaring
> } a local variable in main() [...]?
> 
> Aside from it depending on a particular stack architecture which may
> not be shared by all hardware, it doesn't solve the problem of knowing
> how much stack space will be occupied by the average call frame.
> 
> And even if you could manage to divide the available space by the
> average size, that's still not a guarantee you won't run out if a
> number of frames are larger than average.

I originally thought of average inter-frame step size too, but then
I realized that the code could compare how far it is from main() to
RLIMIT_STACK and bail out gracefully if it has, say, less than X KB or
Y% of stack remaining.

But as you say, that's unportable.  (Not undefined behaviour; just not
guaranteed to be correct.)  Also it really shouldn't be an
application-level concern...



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