[libvirt] [PATCH v2 24/42] openvz: add default: case to all switch statements

Daniel P. Berrangé berrange at redhat.com
Thu Feb 15 16:43:29 UTC 2018


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é <berrange at redhat.com>
---
 src/openvz/openvz_driver.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 9bd73d85c4..6c434dd13c 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1866,6 +1866,9 @@ openvzDomainGetMemoryParameters(virDomainPtr domain,
                                         VIR_TYPED_PARAM_ULLONG, val) < 0)
                 goto cleanup;
             break;
+
+        default:
+            break;
         }
     }
 
-- 
2.14.3




More information about the libvir-list mailing list