[libvirt] [PATCH] virsh: Fix compile error due to const mismatch in cmdVcpupin

Matthias Bolte matthias.bolte at googlemail.com
Mon Jun 20 09:52:24 UTC 2011


2011/6/20 Matthias Bolte <matthias.bolte at googlemail.com>:
> Broken by commit c4a8ca71b10eb adding the reset option.
>
> Instead of altering a const string move the while loop into an
> else clause.
> ---
>  tools/virsh.c |  110 ++++++++++++++++++++++++++++-----------------------------
>  1 files changed, 54 insertions(+), 56 deletions(-)

Here's a version with whitespace changes ignored, for easier review.


diff --git a/tools/virsh.c b/tools/virsh.c
index e04c9fc..0e9efad 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3000,7 +3000,7 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
     int cpumaplen;
     int i, cpu, lastcpu, maxcpu;
     bool unuse = false;
-    char *cur;
+    const char *cur;
     int config = vshCommandOptBool(cmd, "config");
     int live = vshCommandOptBool(cmd, "live");
     int current = vshCommandOptBool(cmd, "current");
@@ -3061,17 +3061,14 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
     cpumap = vshCalloc(ctl, 0, cpumaplen);

     /* Parse cpulist */
-    cur = cpulist;
-    if (*cur == 0) {
+    if (*cpulist == '\0') {
         goto parse_error;
-    } else if (*cur == 'r') {
+    } else if (*cpulist == 'r') {
         for (cpu = 0; cpu < maxcpu; cpu++)
             VIR_USE_CPU(cpumap, cpu);
-        *cur = 0;
-    }
-
-    while (*cur != 0) {
-
+    } else {
+        cur = cpulist;
+        while (*cur != '\0') {
         /* the char '^' denotes exclusive */
         if (*cur == '^') {
             cur++;
@@ -3091,7 +3088,7 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
         }
         virSkipSpaces(&cur);

-        if ((*cur == ',') || (*cur == 0)) {
+            if ((*cur == ',') || (*cur == '\0')) {
             if (unuse) {
                 VIR_UNUSE_CPU(cpumap, cpu);
             } else {
@@ -3123,12 +3120,13 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
             cur++;
             virSkipSpaces(&cur);
             unuse = false;
-        } else if (*cur == 0) {
+            } else if (*cur == '\0') {
             break;
         } else {
             goto parse_error;
         }
     }
+    }

     if (flags == -1) {
         if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0) {


-- 
Matthias Bolte
http://photron.blogspot.com




More information about the libvir-list mailing list