From nobody Wed May 14 18:20:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518541201200681.7036740883664; Tue, 13 Feb 2018 09:00:01 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7663A820F3; Tue, 13 Feb 2018 16:59:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 494585C259; Tue, 13 Feb 2018 16:59:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 123B54A46D; Tue, 13 Feb 2018 16:59:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1DGvD2C009283 for ; Tue, 13 Feb 2018 11:57:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 90555B2890; Tue, 13 Feb 2018 16:57:13 +0000 (UTC) Received: from localhost.localdomain (dhcp-93.gsslab.fab.redhat.com [10.33.9.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30D20B2887; Tue, 13 Feb 2018 16:57:13 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 13 Feb 2018 16:57:06 +0000 Message-Id: <20180213165707.29888-3-berrange@redhat.com> In-Reply-To: <20180213165707.29888-1-berrange@redhat.com> References: <20180213165707.29888-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/3] Fix more switch fallthrough identified by gcc8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 13 Feb 2018 17:00:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 GCC 8 became more fussy/clear about detecting switch fallthroughs. First it doesn't like it if you have a fallthrough attribute that is not before a case statement. e.g. FOO: BAR: WIZZ: ATTRIBUTE_FALLTHROUGH; Is unacceptable as there's no final case statement, so while FOO & BAR are falling through, WIZZ is not falling through. IOW, GCC wants us to write FOO: BAR: ATTRIBUTE_FALLTHROUGH; WIZZ: Second, it will report risk of fallthrough even if you have a case statement for every single enum value, but only if the switch is nested inside another switch and the outer case statement has no final break. This is is in fact valid because despite the fact that we have cast from "int" to the enum typedef, nothing guarantees that the variable we're switching on only contains values that have corresponding switch labels. e.g. int domstate =3D 87539319; switch ((virDomainState)domstate) { ... } will not match enum value, but also not raise any kind of compiler warning. So it is right to complain about risk of fallthrough if no default: is present. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_domain.c | 14 +++++++------- src/qemu/qemu_domain_address.c | 11 +++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f6e28447d..e262588c3 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -175,9 +175,9 @@ qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job, case QEMU_ASYNC_JOB_NONE: case QEMU_ASYNC_JOB_LAST: ATTRIBUTE_FALLTHROUGH; + default: + return "none"; } - - return "none"; } =20 int @@ -199,12 +199,12 @@ qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob = job, case QEMU_ASYNC_JOB_NONE: case QEMU_ASYNC_JOB_LAST: ATTRIBUTE_FALLTHROUGH; + default: + if (STREQ(phase, "none")) + return 0; + else + return -1; } - - if (STREQ(phase, "none")) - return 0; - else - return -1; } =20 =20 diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index e28119e4b..42c7c0b12 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -532,6 +532,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2: /* xen only */ case VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE: case VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST: + default: return 0; } =20 @@ -553,6 +554,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, return pciFlags; =20 case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAST: + default: return 0; } =20 @@ -562,6 +564,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_CONTROLLER_TYPE_FDC: case VIR_DOMAIN_CONTROLLER_TYPE_CCID: case VIR_DOMAIN_CONTROLLER_TYPE_LAST: + default: /* should be 0 */ return pciFlags; } @@ -605,6 +608,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_SOUND_MODEL_PCSPK: case VIR_DOMAIN_SOUND_MODEL_USB: case VIR_DOMAIN_SOUND_MODEL_LAST: + default: return 0; } =20 @@ -622,6 +626,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_DISK_BUS_SATA: case VIR_DOMAIN_DISK_BUS_SD: case VIR_DOMAIN_DISK_BUS_LAST: + default: return 0; } =20 @@ -734,6 +739,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_MEMBALLOON_MODEL_XEN: case VIR_DOMAIN_MEMBALLOON_MODEL_NONE: case VIR_DOMAIN_MEMBALLOON_MODEL_LAST: + default: return 0; } =20 @@ -743,6 +749,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, return virtioFlags; =20 case VIR_DOMAIN_RNG_MODEL_LAST: + default: return 0; } =20 @@ -755,6 +762,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_WATCHDOG_MODEL_IB700: case VIR_DOMAIN_WATCHDOG_MODEL_DIAG288: case VIR_DOMAIN_WATCHDOG_MODEL_LAST: + default: return 0; } =20 @@ -775,6 +783,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_VIDEO_TYPE_DEFAULT: case VIR_DOMAIN_VIDEO_TYPE_GOP: case VIR_DOMAIN_VIDEO_TYPE_LAST: + default: return 0; } =20 @@ -791,6 +800,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_INPUT_BUS_XEN: case VIR_DOMAIN_INPUT_BUS_PARALLELS: case VIR_DOMAIN_INPUT_BUS_LAST: + default: return 0; } =20 @@ -806,6 +816,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SCLP: case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE: case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST: + default: return 0; } =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list