[libvirt] [PATCH v4 01/14] conf: hostdev: Enforce enum-in-switch compile-time checks

Erik Skultety posted 14 patches 8 years, 3 months ago
[libvirt] [PATCH v4 01/14] conf: hostdev: Enforce enum-in-switch compile-time checks
Posted by Erik Skultety 8 years, 3 months ago
Enforce virDomainHostdevSubsysType checking during compilation. Again,
one of a few spots in our code where we should enforce the typecast to
the enum type, thus not forgetting to update *all* switch occurrences
dealing with the give enum.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
---
 src/conf/domain_conf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6bbc6a2a7b..17909820be 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2320,7 +2320,7 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
 
     switch (def->mode) {
     case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
-        switch (def->source.caps.type) {
+        switch ((virDomainHostdevCapsType) def->source.caps.type) {
         case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
             VIR_FREE(def->source.caps.u.storage.block);
             break;
@@ -2331,6 +2331,8 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
             VIR_FREE(def->source.caps.u.net.ifname);
             virNetDevIPInfoClear(&def->source.caps.u.net.ip);
             break;
+        case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
+            break;
         }
         break;
     case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
-- 
2.12.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 01/14] conf: hostdev: Enforce enum-in-switch compile-time checks
Posted by Laine Stump 8 years, 3 months ago
On 03/22/2017 11:27 AM, Erik Skultety wrote:
> Enforce virDomainHostdevSubsysType checking during compilation. Again,
> one of a few spots in our code where we should enforce the typecast to
> the enum type, thus not forgetting to update *all* switch occurrences
> dealing with the give enum.
> 
> Signed-off-by: Erik Skultety <eskultet@redhat.com>
> ---
>  src/conf/domain_conf.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 6bbc6a2a7b..17909820be 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -2320,7 +2320,7 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
>  
>      switch (def->mode) {
>      case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
> -        switch (def->source.caps.type) {
> +        switch ((virDomainHostdevCapsType) def->source.caps.type) {
>          case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
>              VIR_FREE(def->source.caps.u.storage.block);
>              break;
> @@ -2331,6 +2331,8 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
>              VIR_FREE(def->source.caps.u.net.ifname);
>              virNetDevIPInfoClear(&def->source.caps.u.net.ip);
>              break;
> +        case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST:
> +            break;
>          }
>          break;
>      case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
> 

ACK.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list