]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: do not add bools into size calculations
authorJán Tomko <jtomko@redhat.com>
Mon, 5 Oct 2020 16:48:21 +0000 (18:48 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 6 Oct 2020 07:01:46 +0000 (09:01 +0200)
Switch the allocation in virshSnapshotListCollect and
its cargo-culted Checkpoint counterpart to two separate
g_new0 calls and move the boolean expression to
the if condition that chooses between them.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
tools/virsh-checkpoint.c
tools/virsh-snapshot.c

index f3c4fe90baf03efe5ac365efcf774b35484a79bc..cefdfd780023abf702b0035a71ea9fcadf6a4923 100644 (file)
@@ -600,8 +600,10 @@ virshCheckpointListCollect(vshControl *ctl,
 
     /* When mixing --from and --tree, we also want a copy of from
      * in the list, but with no parent for that one entry.  */
-    checkpointlist->chks = vshCalloc(ctl, count + (tree && from),
-                                     sizeof(*checkpointlist->chks));
+    if (from && tree)
+        checkpointlist->chks = g_new0(struct virshChk, count + 1);
+    else
+        checkpointlist->chks = g_new0(struct virshChk, count);
     checkpointlist->nchks = count;
     for (i = 0; i < count; i++)
         checkpointlist->chks[i].chk = chks[i];
index 99e3d98c6f062195686895a7a583134591add181..b4498df29877fee127d8d142894b59483e06ed80 100644 (file)
@@ -1102,8 +1102,10 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
     if (count >= 0) {
         /* When mixing --from and --tree, we also want a copy of from
          * in the list, but with no parent for that one entry.  */
-        snaplist->snaps = vshCalloc(ctl, count + (tree && from),
-                                    sizeof(*snaplist->snaps));
+        if (tree && from)
+            snaplist->snaps = g_new0(struct virshSnap, count + 1);
+        else
+            snaplist->snaps = g_new0(struct virshSnap, count);
         snaplist->nsnaps = count;
         for (i = 0; i < count; i++)
             snaplist->snaps[i].snap = snaps[i];