From patchwork Fri Feb 19 15:34:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 8362161 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9FF509F38B for ; Fri, 19 Feb 2016 15:37:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D10F32034A for ; Fri, 19 Feb 2016 15:37:14 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8AE6A203B1 for ; Fri, 19 Feb 2016 15:37:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aWn5B-00079q-5z; Fri, 19 Feb 2016 15:35:01 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aWn5A-00079b-5H for xen-devel@lists.xensource.com; Fri, 19 Feb 2016 15:35:00 +0000 Received: from [193.109.254.147] by server-2.bemta-14.messagelabs.com id A1/99-12889-32637C65; Fri, 19 Feb 2016 15:34:59 +0000 X-Env-Sender: prvs=8502c4cf5=Ian.Jackson@citrix.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1455896097!25222293!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 44733 invoked from network); 19 Feb 2016 15:34:58 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-10.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 19 Feb 2016 15:34:58 -0000 X-IronPort-AV: E=Sophos;i="5.22,471,1449532800"; d="scan'208";a="332901235" From: Ian Jackson To: Date: Fri, 19 Feb 2016 15:34:49 +0000 Message-ID: <1455896089-6919-1-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian Jackson , Ian Campbell Subject: [Xen-devel] [PATCH] tools: libxl: Simplify logic in libxl__realloc X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the loop exit and separate test for loop overrun with an assert in the loop body. This simplifies the code. It also (hopefully) avoids Coverity thinking that gc->alloc_maxsize might change, resulting in the loop failing to find the right answer but also failing to abort. (gc->alloc_maxsize can't change because gcs are all singlethreaded: either they are on the stack of a specific thread, or they belong to an ao and are covered by the ctx lock.) Signed-off-by: Ian Jackson Acked-by: Ian Campbell --- tools/libxl/libxl_internal.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index fc81130..e7b765b 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -116,16 +116,13 @@ void *libxl__realloc(libxl__gc *gc, void *ptr, size_t new_size) if (ptr == NULL) { libxl__ptr_add(gc, new_ptr); } else if (new_ptr != ptr && libxl__gc_is_real(gc)) { - for (i = 0; i < gc->alloc_maxsize; i++) { + for (i = 0; ; i++) { + assert(i < gc->alloc_maxsize); if (gc->alloc_ptrs[i] == ptr) { gc->alloc_ptrs[i] = new_ptr; break; } } - if (i == gc->alloc_maxsize) { - LOG(CRITICAL, "pointer is not tracked by the given gc"); - abort(); - } } return new_ptr;