From nobody Sun Feb 8 05:40:53 2026 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 1518713571317308.5786543777193; Thu, 15 Feb 2018 08:52:51 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE7757487A; Thu, 15 Feb 2018 16:52:49 +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 B433E5D734; Thu, 15 Feb 2018 16:52:40 +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 79BA04A487; Thu, 15 Feb 2018 16:52:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1FGi9cD025885 for ; Thu, 15 Feb 2018 11:44:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 564BD2024CAA; Thu, 15 Feb 2018 16:44:09 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDD502024CA8; Thu, 15 Feb 2018 16:44:08 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 15 Feb 2018 16:43:35 +0000 Message-Id: <20180215164347.11538-31-berrange@redhat.com> In-Reply-To: <20180215164347.11538-1-berrange@redhat.com> References: <20180215164347.11538-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 30/42] lxc: add default: case to all switch statements 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 15 Feb 2018 16:52:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Even if the compiler has validated that all enum constants have case statements in a switch, it is not safe to omit a default: case statement. When assigning a value to a variable / struct field that is defined with an enum type, nothing prevents an invalid value being assigned. So defensive code must assume existance of invalid values and thus all switches should have a default: case. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/lxc/lxc_controller.c | 1 + src/lxc/lxc_driver.c | 2 ++ src/lxc/lxc_process.c | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index f9f26570cd..3620998100 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -2583,6 +2583,7 @@ int main(int argc, char *argv[]) =20 case 'h': case '?': + default: fprintf(stderr, "\n"); fprintf(stderr, "syntax: %s [OPTIONS]\n", argv[0]); fprintf(stderr, "\n"); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 7d6568cdf8..07fd1f6ebe 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1009,6 +1009,8 @@ lxcDomainGetMemoryParameters(virDomainPtr dom, VIR_TYPED_PARAM_ULLONG, val) < 0) goto cleanup; break; + default: + break; } } =20 diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index bc321e360d..82df80acfd 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -510,6 +510,10 @@ static int virLXCProcessSetupNamespaces(virConnectPtr = conn, if ((nsFDs[i] =3D virLXCProcessSetupNamespaceNet(i, lxcDef->ns= _val[i])) < 0) return -1; break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected namespace source %d"), lxcDef->ns= _source[i]); + return -1; } } =20 @@ -587,13 +591,17 @@ static int virLXCProcessSetupInterfaces(virConnectPtr= conn, case VIR_DOMAIN_NET_TYPE_MCAST: case VIR_DOMAIN_NET_TYPE_UDP: case VIR_DOMAIN_NET_TYPE_INTERNAL: - case VIR_DOMAIN_NET_TYPE_LAST: case VIR_DOMAIN_NET_TYPE_HOSTDEV: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unsupported network type %s"), virDomainNetTypeToString(type)); goto cleanup; =20 + case VIR_DOMAIN_NET_TYPE_LAST: + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected net type %d"), type); + goto cleanup; } =20 /* Set bandwidth or warn if requested and not supported. */ --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list