From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3hIy-00005l-RA for qemu-devel@nongnu.org; Tue, 01 Dec 2015 04:33:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3hIu-0005Bu-PZ for qemu-devel@nongnu.org; Tue, 01 Dec 2015 04:33:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44616) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3hIu-0005Bq-Kk for qemu-devel@nongnu.org; Tue, 01 Dec 2015 04:32:56 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id DBEB2C0D222F for ; Tue, 1 Dec 2015 09:32:55 +0000 (UTC) References: <1448901152-11716-1-git-send-email-armbru@redhat.com> From: Paolo Bonzini Message-ID: <565D6945.2060209@redhat.com> Date: Tue, 1 Dec 2015 10:32:53 +0100 MIME-Version: 1.0 In-Reply-To: <1448901152-11716-1-git-send-email-armbru@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] coverity: Model g_memdup() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org On 30/11/2015 17:32, Markus Armbruster wrote: > We model all the non-deprecated memory allocation functions from > https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html > except for g_memdup(), g_clear_pointer(), g_steal_pointer(). We don't > use the latter two. Model the former. > > Coverity now reports an OVERRUN > vl.c:2317: alloc_strlen: Allocating insufficient memory for the terminating null of the string. > Correct, but we omit the terminating null intentionally there. > > Signed-off-by: Markus Armbruster > --- > scripts/coverity-model.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/scripts/coverity-model.c b/scripts/coverity-model.c > index 617f67d..e1d5f45 100644 > --- a/scripts/coverity-model.c > +++ b/scripts/coverity-model.c > @@ -236,6 +236,23 @@ void *g_try_realloc(void *ptr, size_t size) > return g_try_realloc_n(ptr, 1, size); > } > > +/* Other memory allocation functions */ > + > +void *g_memdup(const void *ptr, unsigned size) > +{ > + unsigned char *dup; > + unsigned i; > + > + if (!ptr) { > + return NULL; > + } > + > + dup = g_malloc(size); > + for (i = 0; i < size; i++) > + dup[i] = ((unsigned char *)ptr)[i]; > + return dup; > +} > + > /* > * GLib string allocation functions > */ > Reviewed-by: Paolo Bonzini