On Fri 08 May 2015 10:06:35 PM CEST, Eric Blake wrote:

>> +    for (i = 0; i < UINT_MAX; i++) {
>> +        QObject *subqobj;
>> +        int subqdict_entries;
>> +        size_t slen = 32 + subqdict_len;
>> +        char indexstr[slen], prefix[slen];
>
> And more dependence on a working C99 compiler, thanks to variable
> length array (VLA).
>
>> +        size_t snprintf_ret;
>> +
>> +        snprintf_ret = snprintf(indexstr, slen, "%s%u", subqdict, i);
>> +        assert(snprintf_ret < slen);
>
> Since gcc may compile the allocation of indexstr into a malloc()
> anyways, would it be any simpler to just use g_strdup_printf()
> directly, instead of futzing around with VLA and snprintf() ourselves?
> It might mean less code, as some of the error checking is taken care
> of on your behalf.

Since the only difference between the two strings you are allocating is
the trailing dot, you could also save one malloc() by reusing the same
string and stripping the dot.

Alternatively you could allocate the memory outside the loop instead of
having to do it in every iteration. The size is always the same after
all.

Berto

Reply via email to