[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [Qemu-block] [PATCH 01/34] qdict: Add qdict_array_entri

From: Alberto Garcia
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 01/34] qdict: Add qdict_array_entries()
Date: Wed, 20 May 2015 16:19:44 +0200
User-agent: Notmuch/0.13.2 (http://notmuchmail.org) Emacs/23.2.1 (i486-pc-linux-gnu)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]