From ed2206cd7051cfe8132d6d31961d13e1cb48832b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Tomko?= Date: Mon, 5 Oct 2020 18:48:21 +0200 Subject: [PATCH] virsh: do not add bools into size calculations MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Erik Skultety --- tools/virsh-checkpoint.c | 6 ++++-- tools/virsh-snapshot.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index f3c4fe90ba..cefdfd7800 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -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]; diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 99e3d98c6f..b4498df298 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -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]; -- 2.47.2