From nobody Fri May 3 09:51:59 2024 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500540392076432.9545660448358; Thu, 20 Jul 2017 01:46:32 -0700 (PDT) Received: from localhost ([::1]:36723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY76M-0007sO-Ad for importer@patchew.org; Thu, 20 Jul 2017 04:46:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY75S-0007ZF-1r for qemu-devel@nongnu.org; Thu, 20 Jul 2017 04:45:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dY75N-0005I7-7f for qemu-devel@nongnu.org; Thu, 20 Jul 2017 04:45:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49910) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dY75N-0005Ht-0r for qemu-devel@nongnu.org; Thu, 20 Jul 2017 04:45:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABB8A7F6B4 for ; Thu, 20 Jul 2017 08:45:27 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-225.ams2.redhat.com [10.36.116.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BAC281B41; Thu, 20 Jul 2017 08:45:24 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 73C0117471; Thu, 20 Jul 2017 10:45:22 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ABB8A7F6B4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ABB8A7F6B4 From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 20 Jul 2017 10:45:22 +0200 Message-Id: <20170720084522.28616-2-kraxel@redhat.com> In-Reply-To: <20170720084522.28616-1-kraxel@redhat.com> References: <20170720084522.28616-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 20 Jul 2017 08:45:27 +0000 (UTC) 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: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/1] usb: Fix build with newer gcc 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: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Eric Blake gcc 7 is pickier about our sources: hw/usb/bus.c: In function =E2=80=98usb_port_location=E2=80=99: hw/usb/bus.c:410:66: error: =E2=80=98%d=E2=80=99 directive output may be tr= uncated writing between 1 and 11 bytes into a region of size between 0 and = 15 [-Werror=3Dformat-truncation=3D] snprintf(downstream->path, sizeof(downstream->path), "%s.%d", ^~ hw/usb/bus.c:410:9: note: =E2=80=98snprintf=E2=80=99 output between 3 and 2= 8 bytes into a destination of size 16 snprintf(downstream->path, sizeof(downstream->path), "%s.%d", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ upstream->path, portnr); ~~~~~~~~~~~~~~~~~~~~~~~ But we know that there are at most 5 levels of USB hubs, with at most two digits per level; that plus the separating dots means we use at most 15 bytes (including trailing NUL) of our 16-byte field. Adding an assertion to show gcc that we checked for truncation is enough to shut up the false-positive warning. Inspired by an idea by Dr. David Alan Gilbert . Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20170717151334.17954-1-eblake@redhat.com Signed-off-by: Gerd Hoffmann --- hw/usb/bus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 5939b273b9..d910f849e7 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -407,8 +407,10 @@ void usb_register_companion(const char *masterbus, USB= Port *ports[], void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr) { if (upstream) { - snprintf(downstream->path, sizeof(downstream->path), "%s.%d", - upstream->path, portnr); + int l =3D snprintf(downstream->path, sizeof(downstream->path), "%s= .%d", + upstream->path, portnr); + /* Max string is nn.nn.nn.nn.nn, which fits in 16 bytes */ + assert(l < sizeof(downstream->path)); downstream->hubcount =3D upstream->hubcount + 1; } else { snprintf(downstream->path, sizeof(downstream->path), "%d", portnr); --=20 2.9.3