4 ms·
why is alloca on this list? is it really that cursed?
by Palomides 6y ago
why is alloca on this list? is it really that cursed?
- swiley 6y agoYes because you have no idea if it's going to result in the stack overwriting the heap. On many compilers it's just a macro that decrements the stack pointer by the value in the argument. You really shouldn't ever use it.
- Palomides 6y agodoesn't that apply to any other function call also? (though obviously alloca can let you do it really fast)
- majewsky 6y agoIIRC, there's a protected page between the stack and the heap, where any reads or writes will `kill -SEGV` the program. With regular function calls, you'll be advancing the stack pointer slowly enough to guarantee a hit on that page. With alloca(), you can move the stack pointer in larger steps, thus missing that page. (The lowest few pages of memory are protected in the same way to increase the likelihood that a NUL pointer correctly blows up in your face when you try to access its memory.)