On Tue, Mar 3, 2015 at 12:56 AM, Anthony J. Bentley <anth...@cathet.us> wrote:
> Evan Gates writes:
>> Declaring variables at the top of a block, as opposed to top of the
>> function has a few uses, but the most useful (in my limited
>> experience) is combining it with C99's variable length arrays to
>> create buffers without calls to malloc/free. For example:
>>
>> while ((d = readdir(dp))) {
>>     char buf[strlen(path) + strlen(d->d_name) + 1];
>>     ....
>> }
>
> VLAs are a fundamentally broken feature because they do not allow any
> error checking. alloca() is the same.
>


alloca() isn't even standard C, that's some black voodoo GNU sorcery
right there.
You should use one buffer, and that buffer's length is some PATH_MAX
or a balloonable realloc.

cheers!
mar77i

Reply via email to