]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh-network: Don't check for virshXXXTypeFromString() >= VIR_XXX_LAST
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Jan 2022 11:59:29 +0000 (12:59 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 19 Jan 2022 15:48:33 +0000 (16:48 +0100)
They way our VIR_ENUM_IMPL() and virXXXTypeFromString() work is
that for any string that's not recognized a negative one is
returned. And, since VIR_XXX_LAST is passed to VIR_ENUM_IMPL() we
can be sure that all enum members are covered. Therefore, there
is no way that virXXXTypeFromString() can return a value that's
bigger or equal to VIR_XXX_LAST.

I've noticed two places where such comparison was made, both in
cmdNetworkUpdate(). Drop them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
tools/virsh-network.c

index 5f574be78cf5cbed97cd8f29c9d955df162a24bd..b2daf31d6b78bc25e9f11203a480b84f36b62277 100644 (file)
@@ -984,7 +984,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd)
         command = VIR_NETWORK_UPDATE_COMMAND_ADD_LAST;
     } else {
         command = virshNetworkUpdateCommandTypeFromString(commandStr);
-        if (command <= 0 || command >= VIR_NETWORK_UPDATE_COMMAND_LAST) {
+        if (command <= 0) {
             vshError(ctl, _("unrecognized command name '%s'"), commandStr);
             goto cleanup;
         }
@@ -994,7 +994,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     section = virshNetworkSectionTypeFromString(sectionStr);
-    if (section <= 0 || section >= VIR_NETWORK_SECTION_LAST) {
+    if (section <= 0) {
         vshError(ctl, _("unrecognized section name '%s'"), sectionStr);
         goto cleanup;
     }