From nobody Thu Nov 13 19:25:46 2025 Delivered-To: importer@patchew.org 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; 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=1582526222; cv=none; d=zohomail.com; s=zohoarc; b=ns4vxPzNmjLrL5QDUM1+lJdLUmy5/+PzVt6CanGBNKiBQErYSH/PfoYW8ukmQVkzc7l6E3EhJIZ993RLjuoe47fnC4Vgo6WTnRnWw0+IAFO1LgmsfcwYNzKWvT+k7DgHV+vohEuWzxye9fii+G5UtTP2WlEWo5kzVW0ALWWJi+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582526222; 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=CQcUubJ536lTN9QMVMFhHJwhXgP6qCCYvhvMxmyhtn8=; b=TkfCBryZuLv4zpmKE3BWJBm+DBJKwG0cvrVjI4odwPzDTha1nBFRcJ0A4cUsL5M6tYLsWk+vrdBg/MjLkCYuc01QG0HiyXGmUxVXWq9AMei6x5ifwgdnQAgedN7qbntE1Y+7pCfONhcFZCm7goAx+0y+C3hxP1Moq6ZaOTeLoIo= 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 1582526222359526.1713603383498; Sun, 23 Feb 2020 22:37:02 -0800 (PST) Received: from localhost ([::1]:60484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j67MR-00059W-Sa for importer@patchew.org; Mon, 24 Feb 2020 01:36:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47023) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j67Lp-0004hY-1d for qemu-devel@nongnu.org; Mon, 24 Feb 2020 01:36:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j67Ln-0003n7-P2 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 01:36:20 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2726 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j67Ln-0003fO-Cu; Mon, 24 Feb 2020 01:36:19 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id DF75691D35F7E514D6B0; Mon, 24 Feb 2020 14:36:12 +0800 (CST) Received: from localhost.localdomain (10.175.104.216) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Mon, 24 Feb 2020 14:36:03 +0800 From: To: , , Subject: [PATCH] target/i386/hax-posix: fix two 'format-truncation' compile warnings Date: Mon, 24 Feb 2020 14:51:39 +0800 Message-ID: <20200224065139.19567-1-pannengyuan@huawei.com> X-Mailer: git-send-email 2.18.2 MIME-Version: 1.0 X-Originating-IP: [10.175.104.216] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 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: qemu-trivial@nongnu.org, euler.robot@huawei.com, Pan Nengyuan , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Pan Nengyuan Fix compile warnings: /mnt/sdb/qemu-new/qemu_test/qemu/target/i386/hax-posix.c:124:56: error: =E2= =80=98%02d=E2=80=99 directive output may be truncated writing between 2 and= 11 bytes into a region of size 3 [-Werror=3Dformat-truncation=3D] snprintf(name, sizeof HAX_VM_DEVFS, "/dev/hax_vm/vm%02d", vm_id); ^~~~ /mnt/sdb/qemu-new/qemu_test/qemu/target/i386/hax-posix.c:124:41: note: dire= ctive argument in the range [-2147483648, 64] snprintf(name, sizeof HAX_VM_DEVFS, "/dev/hax_vm/vm%02d", vm_id); ^~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/stdio.h:873, from /mnt/sdb/qemu-new/qemu_test/qemu/include/qemu/osdep.h= :99, from /mnt/sdb/qemu-new/qemu_test/qemu/target/i386/hax-posi= x.c:14: /usr/include/bits/stdio2.h:67:10: note: =E2=80=98__builtin___snprintf_chk= =E2=80=99 output between 17 and 26 bytes into a destination of size 17 return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /mnt/sdb/qemu-new/qemu_test/qemu/target/i386/hax-posix.c: In function =E2= =80=98hax_vcpu_devfs_string=E2=80=99: /mnt/sdb/qemu-new/qemu_test/qemu/target/i386/hax-posix.c:143:55: error: =E2= =80=98%02d=E2=80=99 directive output may be truncated writing between 2 and= 11 bytes into a region of size 10 [-Werror=3Dformat-truncation=3D] snprintf(name, sizeof HAX_VCPU_DEVFS, "/dev/hax_vm%02d/vcpu%02d", ^~~~ /mnt/sdb/qemu-new/qemu_test/qemu/target/i386/hax-posix.c:143:43: note: dire= ctive argument in the range [-2147483648, 64] snprintf(name, sizeof HAX_VCPU_DEVFS, "/dev/hax_vm%02d/vcpu%02d", ^~~~~~~~~~~~~~~~~~~~~~~~~~ /mnt/sdb/qemu-new/qemu_test/qemu/target/i386/hax-posix.c:143:43: note: dire= ctive argument in the range [-2147483648, 64] In file included from /usr/include/stdio.h:873, from /mnt/sdb/qemu-new/qemu_test/qemu/include/qemu/osdep.h= :99, from /mnt/sdb/qemu-new/qemu_test/qemu/target/i386/hax-posi= x.c:14: /usr/include/bits/stdio2.h:67:10: note: =E2=80=98__builtin___snprintf_chk= =E2=80=99 output between 21 and 39 bytes into a destination of size 21 return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); We know that we have checked the vm_id and vcpu_id in the first(less than 0= x40), it will never be truncated in snprintf(). Thus, this patch add an assertion to clear this false-positive warning. Reported-by: Euler Robot Signed-off-by: Pan Nengyuan --- target/i386/hax-posix.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/target/i386/hax-posix.c b/target/i386/hax-posix.c index a5426a6dac..197d5bc0f9 100644 --- a/target/i386/hax-posix.c +++ b/target/i386/hax-posix.c @@ -121,7 +121,8 @@ static char *hax_vm_devfs_string(int vm_id) return NULL; } =20 - snprintf(name, sizeof HAX_VM_DEVFS, "/dev/hax_vm/vm%02d", vm_id); + int len =3D snprintf(name, sizeof HAX_VM_DEVFS, "/dev/hax_vm/vm%02d", = vm_id); + assert(len < sizeof HAX_VM_DEVFS); return name; } =20 @@ -140,8 +141,9 @@ static char *hax_vcpu_devfs_string(int vm_id, int vcpu_= id) return NULL; } =20 - snprintf(name, sizeof HAX_VCPU_DEVFS, "/dev/hax_vm%02d/vcpu%02d", - vm_id, vcpu_id); + int len =3D snprintf(name, sizeof HAX_VCPU_DEVFS, "/dev/hax_vm%02d/vcp= u%02d", + vm_id, vcpu_id); + assert(len < sizeof HAX_VCPU_DEVFS); return name; } =20 --=20 2.18.2