Received: from eggs.gnu.org ([2001:4830:134:3::10]:35993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WBfxw-0002gr-QB for qemu-devel@nongnu.org; Fri, 07 Feb 2014 02:35:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WBfxr-0003AH-GN for qemu-devel@nongnu.org; Fri, 07 Feb 2014 02:35:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WBfxr-00037U-8T for qemu-devel@nongnu.org; Fri, 07 Feb 2014 02:35:07 -0500 From: Markus Armbruster References: <1391697000-5855-1-git-send-email-armbru@redhat.com> <1391697000-5855-11-git-send-email-armbru@redhat.com> <52F44EB1.8010306@redhat.com> Date: Fri, 07 Feb 2014 08:34:58 +0100 In-Reply-To: <52F44EB1.8010306@redhat.com> (Eric Blake's message of "Thu, 06 Feb 2014 20:10:41 -0700") Message-ID: <87zjm39xzx.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 10/10] qapi: Clean up null checking in generated visitors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, qemu-devel@nongnu.org, aliguori@amazon.com, mdroth@linux.vnet.ibm.com Eric Blake writes: > On 02/06/2014 07:30 AM, Markus Armbruster wrote: >> Visitors get passed a pointer to the visited object. The generated >> visitors try to cope with this pointer being null in some places, for >> instance like this: >> >> visit_start_optional(m, obj ? &(*obj)->has_name : NULL, "name", &err); >> >> visit_start_optional() passes its second argument to Visitor method >> start_optional. Two out of two methods dereference it >> unconditionally. > > Let's see if I can find them without Coverity's help... > > opts-visitor.c:opts_start_optional > qmp-input-visitor.c:qmp_input_start_optional > string-input-visitor.c:parse_start_optional > > Your counting is off :) All three unconditionally dereference. Right. I can't count :) Most Coverity's defects are about silliness like this: visit_start_optional(m, obj ? &(*obj)->has_name : NULL, "name", &err); if (obj && (*obj)->has_name) { visit_type_str(m, obj ? &(*obj)->name : NULL, "name", &err); } The second "obj ? ... : ..." is guarded by if (obj), thus cannot take the false branch. > [While at it, this code style from parse_start_optional, and similar in > other locations, is rather verbose: > > if (!siv->string) { > *present = false; > return; > } > > *present = true; > } > > Shorter would be: > > *present = !!siv->string; > } > > but that doesn't affect this patch] Coccinelle job, if I can teach it our macros. Without that, it frequently chokes on some macro usage, leaving too much code unexamined. >> I fail to see how hits pointer could legitimately be null. >> >> All this useless null checking is highly redundant, which Coverity >> duly reports. About 200 times. >> >> Remove the useless null checks. >> >> Signed-off-by: Markus Armbruster >> --- >> scripts/qapi-visit.py | 14 +++++++------- >> 1 file changed, 7 insertions(+), 7 deletions(-) > > Reviewed-by: Eric Blake