[CGit] [PATCH v2 2/6] new_filter: correctly initialise all arguments for a new filter

Ferry Huberts mailings at hupie.com
Sun Mar 6 22:24:28 CET 2011


On 03/06/2011 03:44 PM, Lars Hjemli wrote:
> On Fri, Mar 4, 2011 at 01:31, Ferry Huberts <mailings at hupie.com> wrote:
>> @@ -36,8 +37,10 @@ struct cgit_filter *new_filter(const char *cmd, int extra_args)
>>        f = xmalloc(sizeof(struct cgit_filter));
>>        f->cmd = xstrdup(cmd);
>>        f->argv = xmalloc((2 + extra_args) * sizeof(char *));
>> -       f->argv[0] = f->cmd;
>> -       f->argv[1] = NULL;
>> +       f->argv[i++] = f->cmd;
>> +       while (i < (2 + extra_args)) {
>> +         f->argv[i++] = NULL;
>> +       }
>>        return f;
>>  }
> 
> Maybe something like this instead?
> 
>   size = (2 + extra_args) * sizeof(char *);
>   f->argv = xmalloc(size);
>   memset(argv, 0, size);
> 
> --
> larsh

sure.
I just kept it in the same code style.
As long as it is fixed, because the argument list HAS to be terminated
with a NULL pointer (accoring to the execve man page) and this currently
does not happen for the source filter, which can result to some very
strange consequences.


-- 
Ferry Huberts




More information about the CGit mailing list