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é <berra...@redhat.com> --- po/POTFILES.in | 1 + src/secret/secret_util.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 2859554690..e06aa730f8 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -166,6 +166,7 @@ src/rpc/virnetsocket.c src/rpc/virnetsshsession.c src/rpc/virnettlscontext.c src/secret/secret_driver.c +src/secret/secret_util.c src/security/security_apparmor.c src/security/security_dac.c src/security/security_driver.c diff --git a/src/secret/secret_util.c b/src/secret/secret_util.c index 16e43ab2cc..64d3e7b8bd 100644 --- a/src/secret/secret_util.c +++ b/src/secret/secret_util.c @@ -57,7 +57,7 @@ virSecretGetSecretString(virConnectPtr conn, virSecretPtr sec = NULL; int ret = -1; - switch (seclookupdef->type) { + switch ((virSecretLookupType)seclookupdef->type) { case VIR_SECRET_LOOKUP_TYPE_UUID: sec = conn->secretDriver->secretLookupByUUID(conn, seclookupdef->u.uuid); break; @@ -66,6 +66,15 @@ virSecretGetSecretString(virConnectPtr conn, sec = conn->secretDriver->secretLookupByUsage(conn, secretUsageType, seclookupdef->u.usage); break; + + case VIR_SECRET_LOOKUP_TYPE_NONE: + break; + + case VIR_SECRET_LOOKUP_TYPE_LAST: + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected secret lookup type %d"), seclookupdef->type); + goto cleanup; } if (!sec) -- 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list