Received: from eggs.gnu.org ([2001:4830:134:3::10]:41889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3xbe-00028D-9W for qemu-devel@nongnu.org; Mon, 29 Jul 2013 20:16:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3xbY-00076r-7S for qemu-devel@nongnu.org; Mon, 29 Jul 2013 20:16:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3xbY-00076f-06 for qemu-devel@nongnu.org; Mon, 29 Jul 2013 20:15:56 -0400 From: Markus Armbruster References: <1374201401-11244-1-git-send-email-p.pawit@gmail.com> <51E91BAF.4050903@redhat.com> <20130729170523.4e6a62eb@redhat.com> Date: Tue, 30 Jul 2013 02:15:50 +0200 In-Reply-To: <20130729170523.4e6a62eb@redhat.com> (Luiz Capitulino's message of "Mon, 29 Jul 2013 17:05:23 -0400") Message-ID: <87d2q0q4w9.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] migration: don't use uninitialized variables List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: Pawit Pornkitprasan , qemu-devel@nongnu.org, Ryousei Takano , Juan Quintela Luiz Capitulino writes: > On Fri, 19 Jul 2013 04:57:51 -0600 > Eric Blake wrote: > >> On 07/18/2013 08:36 PM, Pawit Pornkitprasan wrote: >> > The qmp_migrate method uses the 'blk' and 'inc' parameter without >> > checking if they're valid or not (they may be uninitialized if >> > command is received via QMP) >> > >> > Signed-off-by: Pawit Pornkitprasan >> > --- >> > migration.c | 4 ++-- >> > 1 file changed, 2 insertions(+), 2 deletions(-) >> >> Reviewed-by: Eric Blake >> >> However, wouldn't it be nice if we improved the qapi generator to >> guarantee a sane default value for optional parameters, even when >> has_value is false? > > We could do that for bool and pointers, but this wouldn't help > integers and enums. Also, even if we had default values, I guess > I'd enforce a common idiom for handling optionals as this is also > a good practice for preventing bugs. I disagree on pointers. "have_ptr && ptr->..." is a stupid idiom. The common idiom for safe dereference is "ptr && ptr->...". "bool have_ptr, FOO *ptr" in a parameter list is unidiomatic C. Idiomatic is just "FOO *ptr". Conciseness is a virtue. For non-pointers, there's no special "don't have one" value, so we'd have to declare a default value in the schema to get rid of the have_FOO.