From nobody Fri Nov 7 04:04:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545534307878449.41637757283627; Sat, 22 Dec 2018 19:05:07 -0800 (PST) Received: from localhost ([::1]:57574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gau4g-0007GG-N6 for importer@patchew.org; Sat, 22 Dec 2018 22:05:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gau0x-00050Z-I5 for qemu-devel@nongnu.org; Sat, 22 Dec 2018 22:01:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gau0w-0005kp-KW for qemu-devel@nongnu.org; Sat, 22 Dec 2018 22:01:15 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:38859) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gau0u-0005bu-Lg; Sat, 22 Dec 2018 22:01:14 -0500 Received: by mail-pl1-x641.google.com with SMTP id e5so4253973plb.5; Sat, 22 Dec 2018 19:01:05 -0800 (PST) Received: from localhost.localdomain (114-136-27-106.emome-ip.hinet.net. [114.136.27.106]) by smtp.gmail.com with ESMTPSA id g190sm32610180pgc.28.2018.12.22.19.01.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Dec 2018 19:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L1FR6ELX1uVFNnHrkM+ggycxAznG+B07guu3n9P38XE=; b=OBzb2wHtSmLwZqqJ73PAIwnx13iGUz+hARr+pLgYBnGVpCvEb15wtmlr9jbNNTQXGw 6eF1Y2b8cOJAAq6TaolvnbsBQORCZkGVVGvKOO533mhZ8D72oLlmQIzZTsdZXnlq+9GY CnudNg4BdcEcx4nVkmCD2KnR8cZao1zFeqmSXpUgV/WcO5CL080OZgxrBxyb+sXIGrMV Op5gi/WWyDuwY/owa6m+8ZHRchADrTPizKFF2K/rJG5upsKLdapMII97q6Q3UfN0z1pk RhmXZ8QiTkPPxvBxodXlW3QiDk22JzeG6WoVFZCvb7+Frz4Kx4F7PmqxWJzR5Hg95XFN Gqcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L1FR6ELX1uVFNnHrkM+ggycxAznG+B07guu3n9P38XE=; b=KoJIfSXULa+aGQVuVwMj2u5RcoaTbVmtMmSmufWoS0QpVNcYV+7BLY93U2bNJ6eC9f T72WTXDhKVLMWCgMhbge/4yk9I5xDfzfJHRsUWlrnFnL8zaTDGzqJRyX5+Ml3LjPPhcB PB3gCHhXCZjZXsgTw70pulGLJf4gbDDXsq2Etj9GBhpG7DvDHBeVMN6VOcNA03KWAjkb V9bNsATLaZ6FDUkZxVt0arscNhKKOpSLkyBnBIUskuD7IkqmwQptuK+i1E0E1ruP5cZQ zaiTdT9opy12V7lIsmgAuMCmAgxdGHdkZG8xZoHLT7rGrTTYIrJJM6GN9jEdJDfHObqK ASOQ== X-Gm-Message-State: AJcUukdehvOHHxmcNuxzkgNW1PsVwoWyB/wGku8bh6U4mgsKsvoJUosM Kjocc6SFgvyLpmrvYgAq1CogHSiLvys= X-Google-Smtp-Source: ALg8bN795x5809+s0w6bazF4CbwGeNcQjKWYk+qbJIJJBJagTlRJGSJzhimBpgRDzWalnO7UyTh/2A== X-Received: by 2002:a17:902:2868:: with SMTP id e95mr8454480plb.317.1545534063892; Sat, 22 Dec 2018 19:01:03 -0800 (PST) From: yuchenlin To: qemu-devel@nongnu.org Date: Sun, 23 Dec 2018 10:59:37 +0800 Message-Id: <20181223025939.15775-2-npes87184@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181223025939.15775-1-npes87184@gmail.com> References: <20181223025939.15775-1-npes87184@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH v2 1/3] dmg: fix binary search X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yuchenlin , qemu-block@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There is a possible hang in original binary search implementation. That is if chunk1 =3D 4, chunk2 =3D 5, chunk3 =3D 4, and we go else case. The chunk1 will be still 4, and so on. Signed-off-by: yuchenlin Reviewed-by: Julio Faracco --- block/dmg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/dmg.c b/block/dmg.c index 50e91aef6d..0e05702f5d 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -572,14 +572,14 @@ static inline uint32_t search_chunk(BDRVDMGState *s, = uint64_t sector_num) { /* binary search */ uint32_t chunk1 =3D 0, chunk2 =3D s->n_chunks, chunk3; - while (chunk1 !=3D chunk2) { + while (chunk1 <=3D chunk2) { chunk3 =3D (chunk1 + chunk2) / 2; if (s->sectors[chunk3] > sector_num) { - chunk2 =3D chunk3; + chunk2 =3D chunk3 - 1; } else if (s->sectors[chunk3] + s->sectorcounts[chunk3] > sector_n= um) { return chunk3; } else { - chunk1 =3D chunk3; + chunk1 =3D chunk3 + 1; } } return s->n_chunks; /* error */ --=20 2.17.1