2 ms·
The issue with VLAs (variable length arrays) is that what tends to happen is that programmers create a denial-of-service bug. It's easy to do-- just create a V
by cmccabe 14y ago
The issue with VLAs (variable length arrays) is that what tends to happen is that programmers create a denial-of-service bug. It's easy to do-- just create a VLA without first checking to make sure the size isn't too big. Then invalid (or sometimes even valid) input may lead you to use too much stack space, and-- boom! Segfault. These segfaults can be hard to reproduce because stack sizes can vary between machines or depending on which code path you call the function in. This is why Google banned VLAs in their coding standard.
If you're absolutely sure that you can handle the power, you can always call alloca and get some stack-allocated space, even with ancient C compilers. Just make sure to enforce a reasonable upper limit. Also, never mix C99-style arrays and alloca.