Is replacing alloca(3) where possible a good thing to do?

twilight pipfstarrd at openmailbox.org
Wed Sep 14 16:02:32 UTC 2016


> The one time I tried to use it, it went very badly, as it returns a
> pointer, but the actual amount of memory was less than I had requested,
> and so it smashed everything.

That is a known issue with alloca, so it shouldn't be used with big
amounts of memory (it creates objects on stack, so stack overflow can be
reached easily).

But, well, creating a really big array would do the same. Also, deep
recursion will also smash the stack.

So we don't have a deal like "remove alloca and your stack will be
safe". But still, it's obsolete and compiler dependent. I'd better not
stick to it.
-- 
Cheers~

PGP key fingerprint:
07B3 2177 3E27 BF41 DC65  CC95 BDA8 88F1 E9F9 CEEF

You can retrieve my public key at pgp.mit.edu.


More information about the freebsd-hackers mailing list