:: Re: [DNG] "Common knowledge?"-quest…
Góra strony
Delete this message
Reply to this message
Autor: Peter Olson
Data:  
Dla: dng, Rainer Weikusat
Temat: Re: [DNG] "Common knowledge?"-question
> On January 23, 2016 at 1:36 PM Rainer Weikusat
> <rainerweikusat@???> wrote:
>
> Peter Olson <peabo@???> writes:
> 5>> On January 22, 2016 at 4:34 PM Rainer Weikusat
> <rainerweikusat@???> wrote:
>
> [...]
>
> >>     p = buf = alloca(total);

>
> [...]
>
> > the failure mode of alloca is SIGSEGV or some other malfunction and
> > there is no way to test for it
>
> It's supposed to allocate memory in the current stack frame which will
> work unless the stack has already grown to the limit.


>From man7.org/linux/man-pages/man3/alloca.3.html section BUGS:

       There is no error indication if the stack frame cannot be extended.
       (However, after a failed allocation, the program is likely to receive
       a SIGSEGV signal if it attempts to access the unallocated space.)


I have never been a fan of alloca though it obviously _can_ be used safely with
a little care. The hazard of passing a very long string by accident is what
makes it unsafe. In this case, with short enough strings it is no more
hazardous than a recursion that is too deep.

Peter Olson