From c5e8d51824fe725d0693cd9f50171d34297c5cc0 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 23 Sep 2022 10:42:54 +0200 Subject: Use g_new() & friends where that makes obvious sense g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors. This commit only touches allocations with size arguments of the form sizeof(T). Patch created mechanically with: $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \ --macro-file scripts/cocci-macro-file.h FILES... The previous iteration was commit a95942b50c. Signed-off-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Message-Id: <20220923084254.4173111-1-armbru@redhat.com> Signed-off-by: Laurent Vivier --- migration/dirtyrate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'migration') diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 795fab5..d6f1e01 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -119,9 +119,9 @@ static DirtyPageRecord *vcpu_dirty_stat_alloc(VcpuStat *stat) } stat->nvcpu = nvcpu; - stat->rates = g_malloc0(sizeof(DirtyRateVcpu) * nvcpu); + stat->rates = g_new0(DirtyRateVcpu, nvcpu); - records = g_malloc0(sizeof(DirtyPageRecord) * nvcpu); + records = g_new0(DirtyPageRecord, nvcpu); return records; } -- cgit v1.1