From patchwork Thu Mar 12 06:09:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 449311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E2956140142 for ; Thu, 12 Mar 2015 17:10:17 +1100 (AEDT) Received: from localhost ([::1]:58154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVwJx-000404-L6 for incoming@patchwork.ozlabs.org; Thu, 12 Mar 2015 02:10:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVwJh-0003el-71 for qemu-devel@nongnu.org; Thu, 12 Mar 2015 02:09:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVwJe-0001Ik-1X for qemu-devel@nongnu.org; Thu, 12 Mar 2015 02:09:57 -0400 Received: from mout.web.de ([212.227.15.14]:61279) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVwJd-0001Ic-Nv for qemu-devel@nongnu.org; Thu, 12 Mar 2015 02:09:53 -0400 Received: from md1f2u6c.ww002.siemens.net ([95.157.58.223]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0MEIQq-1YlJRs0Ye0-00FTx1; Thu, 12 Mar 2015 07:09:48 +0100 Message-ID: <55012DAB.7080007@web.de> Date: Thu, 12 Mar 2015 07:09:47 +0100 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Markus Armbruster X-Provags-ID: V03:K0:lHbwtqI7d5vX1JyMAoCLQ4TTMJrjtk0MCt/4SAEqChJYSNBKJ/P JsNQv42nUUWk6tMXlh0xZOmP+mvSH6NfTLkkBrtFN/PTf7aoJ4eGHEoycOm/q6cZeLA3OWh RWGhBS36zRuYQOoKPMYSMgGcPNFlpUxyEnXpBxyy/oon48BAKsDvkZYFin6Eq7ZZZBCcJ0Y lSh4Tx90OTWAskpm16c8w== X-UI-Out-Filterresults: notjunk:1; X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 212.227.15.14 Cc: qemu-devel Subject: [Qemu-devel] Coverity model of g_malloc_n & Co. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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? If so, I can file a proper patch later. Jan 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