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 Sat, Apr 15, 2017 at 09:14:56 -0700:
> If not for the variable thrown in by the compiler options it might be
> possible for zsh to estimate a value for max function depth at the
> time it starts up, by examining the current limits,
>

Hmm.  Would it work to measure the stack space used, by declaring
a local variable in main(), stashing its address in a global write-once
variable, and then subtracting the address of a function-local variable
from the global?  That is:

    extern const void *top_of_stack;
    main() {
        const int x = …;
        top_of_stack = &x;
        ⋮
    }
    foo() {
        int x;
        printf("Stack space in use: %llu\n", (unsigned long long)(top_of_stack - &x));
    }

(I somewhat expect this to be a bad idea...)

> but there's also no guarantee that the limit settings reflect the
> actual amount of stack available.



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