Received: from eggs.gnu.org ([2001:4830:134:3::10]:52437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVxDj-00023U-VH for qemu-devel@nongnu.org; Mon, 22 Sep 2014 02:35:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVxDd-0004qT-J5 for qemu-devel@nongnu.org; Mon, 22 Sep 2014 02:35:35 -0400 From: Markus Armbruster References: <1411171901-13792-1-git-send-email-akong@redhat.com> <541D1D9A.6020100@redhat.com> Date: Mon, 22 Sep 2014 08:35:18 +0200 In-Reply-To: <541D1D9A.6020100@redhat.com> (Paolo Bonzini's message of "Sat, 20 Sep 2014 08:24:26 +0200") Message-ID: <87lhpcw4bd.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] qom: suppress conscan warning of returning null point List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: jen@redhat.com, qemu-trivial@nongnu.org, qemu-devel@nongnu.org, aliguori@amazon.com, Amos Kong , afaerber@suse.de Paolo Bonzini writes: > Il 20/09/2014 02:11, Amos Kong ha scritto: >> Conscan complains about g_malloc0() and malloc() return null. s/Conscan/Coverity/, both here and in subject. >> >> Error: NULL_RETURNS (CWE-476): >> qemu-kvm/qom/object.c:239: returned_null: Function >> "g_malloc0(gsize)" returns null. >> qemu-kvm/qom/object.c:239: var_assigned: Assigning: "ti->class" = >> null return value from "g_malloc0(gsize)". >> qemu-kvm/qom/object.c:249: dereference: Dereferencing a null >> pointer "ti->class". >> >> But if the passed size parameter is >= 1, then we can always get an >> effective pointer, the warning disappears. > > The model should handle it: > > void * > g_malloc0(size_t n_bytes) > { > void *mem; > __coverity_negative_sink__(n_bytes); > mem = calloc(1, n_bytes == 0 ? 1 : n_bytes); > if (!mem) __coverity_panic__(); > return mem; > } > > So this patch means your coverity runs are misconfigured. Yes. I'm not sure we want the assertions anyway. I use the following options with cov-analyze: -co BAD_FREE:allow_first_field:true -co DEADCODE:no_dead_default:true --security --concurrency --user-model-file scripts/coverity-model.xmldb --derived-model-file ~/work/glib/glib-2.38.2.xmldb where glib-2.38.2.xmldb is produced by "cov-collect-models --dir cov -of glib-2.32.4.xmldb" after a full Coverity scan of glib.