From nobody Mon Nov 17 13:51:42 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604554884; cv=none; d=zohomail.com; s=zohoarc; b=Ma93uMYrPWdA8j10Msua/4vzSjTxlSFLUS938R9LEXeHWhbqZQTnZK7JMawDXFmavBFkyEyDzo9cyO9GfrBaACObTGMB863uQkVrMfBd13NY/53PtBPN5xsOiV+XgXM2u5VSC0HhOrQRbUpurvnlsWVI1TCApYQFYiEdesZG21g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604554884; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=2/I2ve40bOl9c88ovtdvhLmRFWUhstV0+RzVDfT9wsg=; b=VJJW8BmsMGqepKOJiW1uWoh6s2IsdQ8gcKezCU2z73FoQfbwmz97HXJl1/luzydTj3rAh6HjT/lTb1Fk66zdJ54i1b2naqzkNJ0yfCLwnDj+HeLtQS9EH3Psu/Dm5C7MQfCHNLUhIItCaTUVX4NlmjYt4/V5tZGCqPZ8lkD2WBY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604554883853891.6097544952589; Wed, 4 Nov 2020 21:41:23 -0800 (PST) Received: from localhost ([::1]:48000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kaY1R-0003qL-Va for importer@patchew.org; Thu, 05 Nov 2020 00:41:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kaY0f-0003L8-TK; Thu, 05 Nov 2020 00:40:33 -0500 Received: from smtp.h3c.com ([60.191.123.56]:56563 helo=h3cspam01-ex.h3c.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kaY0Y-0001t2-W9; Thu, 05 Nov 2020 00:40:33 -0500 Received: from DAG2EX02-BASE.srv.huawei-3com.com ([10.8.0.65]) by h3cspam01-ex.h3c.com with ESMTPS id 0A55e425049535 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 5 Nov 2020 13:40:04 +0800 (GMT-8) (envelope-from tu.guoyi@h3c.com) Received: from DAG2EX03-BASE.srv.huawei-3com.com (10.8.0.66) by DAG2EX02-BASE.srv.huawei-3com.com (10.8.0.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Thu, 5 Nov 2020 13:40:06 +0800 Received: from DAG2EX03-BASE.srv.huawei-3com.com ([fe80::5d18:e01c:bbbd:c074]) by DAG2EX03-BASE.srv.huawei-3com.com ([fe80::5d18:e01c:bbbd:c074%7]) with mapi id 15.01.2106.002; Thu, 5 Nov 2020 13:40:06 +0800 From: Tuguoyi To: Kevin Wolf , Max Reitz , "qemu-block@nongnu.org" Subject: [PATCH] block: Fix integer promotion error in bdrv_getlength() Thread-Topic: [PATCH] block: Fix integer promotion error in bdrv_getlength() Thread-Index: AdazNZvDJjXIINNtSs2+W7uMUYNirQ== Date: Thu, 5 Nov 2020 05:40:06 +0000 Message-ID: Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.125.108.131] x-sender-location: DAG2 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DNSRBL: X-MAIL: h3cspam01-ex.h3c.com 0A55e425049535 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=60.191.123.56; envelope-from=tu.guoyi@h3c.com; helo=h3cspam01-ex.h3c.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/05 00:40:18 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chengchiwen , "qemu-devel@nongnu.org" , Wangyong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" As BDRV_SECTOR_SIZE is of type uint64_t, the expression will automatically convert the @ret to uint64_t. When an error code returned from bdrv_nb_sectors(), the promoted @ret will be a very large number, as a result the -EFBIG will be returned which is not the real error code. Signed-off-by: Guoyi Tu --- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block.c b/block.c index 430edf7..f14254c 100644 --- a/block.c +++ b/block.c @@ -5082,7 +5082,7 @@ int64_t bdrv_getlength(BlockDriverState *bs) { int64_t ret =3D bdrv_nb_sectors(bs); =20 - ret =3D ret > INT64_MAX / BDRV_SECTOR_SIZE ? -EFBIG : ret; + ret =3D ret > INT64_MAX / (int64_t)BDRV_SECTOR_SIZE ? -EFBIG : ret; return ret < 0 ? ret : ret * BDRV_SECTOR_SIZE; } =20 --=20 2.7.4 Please ignore the [PATCH] block: Return the real error code in bdrv_getleng= th -- Best regards, Guoyi