Received: from eggs.gnu.org ([2001:4830:134:3::10]:46217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YW0nL-0001vK-Tw for qemu-devel@nongnu.org; Thu, 12 Mar 2015 06:56:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YW0nG-0002KH-RX for qemu-devel@nongnu.org; Thu, 12 Mar 2015 06:56:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YW0nG-0002KD-IV for qemu-devel@nongnu.org; Thu, 12 Mar 2015 06:56:46 -0400 From: Markus Armbruster References: <55012DAB.7080007@web.de> Date: Thu, 12 Mar 2015 11:56:41 +0100 In-Reply-To: <55012DAB.7080007@web.de> (Jan Kiszka's message of "Thu, 12 Mar 2015 07:09:47 +0100") Message-ID: <87zj7io55i.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] Coverity model of g_malloc_n & Co. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: qemu-devel Jan Kiszka writes: > Hi Markus, > > due to a lack of publicly available documentation on the Coverity > modeling language (or my blindness to find it), I was about to steal > some patterns from QEMU (to improve the kmalloc model for the kernel). I > think I stumbled over some inconsistency: Don't we need to allocate the > calculated size here, not the passed one? > > diff --git a/scripts/coverity-model.c b/scripts/coverity-model.c > index 58356af..cdda259 100644 > --- a/scripts/coverity-model.c > +++ b/scripts/coverity-model.c > @@ -123,7 +123,7 @@ void *g_malloc_n(size_t nmemb, size_t size) > __coverity_negative_sink__(nmemb); > __coverity_negative_sink__(size); > sz = nmemb * size; > - ptr = __coverity_alloc__(size); > + ptr = __coverity_alloc__(sz); > __coverity_mark_as_uninitialized_buffer__(ptr); > __coverity_mark_as_afm_allocated__(ptr, "g_free"); > return ptr; > @@ -137,7 +137,7 @@ void *g_malloc0_n(size_t nmemb, size_t size) > __coverity_negative_sink__(nmemb); > __coverity_negative_sink__(size); > sz = nmemb * size; > - ptr = __coverity_alloc__(size); > + ptr = __coverity_alloc__(sz); > __coverity_writeall0__(ptr); > __coverity_mark_as_afm_allocated__(ptr, "g_free"); > return ptr; > @@ -151,7 +151,7 @@ void *g_realloc_n(void *ptr, size_t nmemb, size_t size) > __coverity_negative_sink__(size); > sz = nmemb * size; > __coverity_escape__(ptr); > - ptr = __coverity_alloc__(size); > + ptr = __coverity_alloc__(sz); > /* > * Memory beyond the old size isn't actually initialized. Can't > * model that. See Coverity's realloc() model > > If so, I can file a proper patch later. You're right! Please submit a patch.