Received: from eggs.gnu.org ([2001:4830:134:3::10]:55257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yv4qf-0005M9-O5 for qemu-devel@nongnu.org; Wed, 20 May 2015 10:19:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yv4qf-0004Nd-29 for qemu-devel@nongnu.org; Wed, 20 May 2015 10:19:53 -0400 From: Alberto Garcia In-Reply-To: <554D174B.4010200@redhat.com> References: <1431105726-3682-1-git-send-email-kwolf@redhat.com> <1431105726-3682-2-git-send-email-kwolf@redhat.com> <554D174B.4010200@redhat.com> Date: Wed, 20 May 2015 16:19:44 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 01/34] qdict: Add qdict_array_entries() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , Kevin Wolf , qemu-block@nongnu.org Cc: armbru@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com 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